Solved

TRACKMOUSEEVENT help

Posted on 2003-10-27
6
300 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:ragin_cajun
Comment Utility
Hi Andy -

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

Author Comment

by:ragin_cajun
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now