Solved

TRACKMOUSEEVENT help

Posted on 2003-10-27
6
310 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
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!

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 102
twoTwo  challenge 35 112
Thin secure Windows 10 5 107
Problem to App 4 118
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

749 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