Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

TRACKMOUSEEVENT help

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
ragin_cajun
Asked:
ragin_cajun
  • 3
  • 2
1 Solution
 
AlexFMCommented:
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
 
ragin_cajunAuthor Commented:
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
 
AndyAinscowCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ragin_cajunAuthor Commented:
Hi Andy -

Where / how do I override the PreTranslateMessageFunction?
0
 
ragin_cajunAuthor Commented:
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
 
AndyAinscowCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now