Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

TRACKMOUSEEVENT help

Posted on 2003-10-27
6
309 Views
Last Modified: 2013-11-20
Hi,

I'm trying to simulate a rollover in mfc. I got the coordinates of my static text control, I set up my ON_MOUSEMOVE function to detect what coordinate the mouse is at - now when the mouse is within the area of the static text it doesn't respond. However if I declare a random hot spot rect elsewhere in the client area and move the mouse in that area I'll get the expected response.

I'm guessing my problem is that the static text control is a window itself so the parent window isn't doing anything with the mouse messages when the mouse is over it. I've been reading and it seems TRACKMOUSEEVENT is what I should use to determine if the mouse is over the static text control.

I set up my struct like:

TRACKMOUSEEVENT mouseHover;
mouseHover.cbSize = sizeof(mouseHover);
mouseHover.dwFlags = TME_HOVER;
mouseHover.dwHoverTime = 1;
mouseHover.hwndTrack = my_static_text_control.GetSafeHwnd();

if(TrackMouseEvent(&mouseHover) ) //  what should i replace this with!
{
    AfxMessageBox("success");
}

But this isn't working as when my mouse moves anywhere in the dialog it'll generate the message box, I want it to succeed only when the mouse moves over the static text.


Thanks.
0
Comment
Question by:ragin_cajun
  • 3
  • 2
6 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9631831
Write your own class derived from CStatic. Create CStatic class member in dialog using MFC Class Wizard, replace manually CStatic class with your own CStatic-derived class. Hanle WM_MOUSEMOVE in this class.
0
 
LVL 1

Author Comment

by:ragin_cajun
ID: 9634171
Can you provide a code sample or a link to one - I'm using vc .NET - I read how to subclass a control using vc 6 but in .NET the class wizard doesn't let you create a class on a control with a base class other than CDialog etc (basically not CStatic).

There isn't any way to draw a rect over the control that the parent dialog can still process messages to so I can just hit test that?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 90 total points
ID: 9634434
Set the NOTIFY property of your static to TRUE in the resource editor and override the PreTranslateMessage function

Put the following (or similar) code in place
      if((pMsg->message == WM_MOUSEMOVE) && (pMsg->hwnd == GetDlgItem(IDC_STATIC1)->GetSafeHwnd()))
            TRACE("Over");
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:ragin_cajun
ID: 9635048
Hi Andy -

Where / how do I override the PreTranslateMessageFunction?
0
 
LVL 1

Author Comment

by:ragin_cajun
ID: 9635520
Ahh I got it - that worked perfectly Andy thanks for your solution. It worked for scroll bars and other controls as well even though there is no option on those for NOTIFY in the resource editor.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9637229
Static controls DON'T notify the parent with events by default.  Most other controls do (because the user can usually manipulate them).

The PreTranslateMessage is a very useful  function to trap windows messages before they are passed to controls.  Return TRUE to say you have done some customised behaviour else FALSE to let it do the default.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 130
Replacement selected text 2 63
sameEnds challenge 3 179
scoreUp challenge 14 63
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question