Solved

TRACKMOUSEEVENT help

Posted on 2003-10-27
6
318 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
[X]
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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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. …
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

623 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