Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to detect mouse over buttons in a dialog?

779 views
Skip to first unread message

Weiyang Zhou

unread,
Apr 22, 2003, 11:32:07 AM4/22/03
to
I tried to override the CWnd::OnMouseMove in the dialog class to detect if
the mouse is over buttons in a dialog. But I found out when the mouse is
over a button, Windows stops sending WM_MOUSEMOVE message, so I will not be
able to test if the point is inside the button rectangle.

Does anyone know a better way to test if mouse if over buttons?

Weiyang


David Lowndes

unread,
Apr 22, 2003, 12:37:32 PM4/22/03
to
>I tried to override the CWnd::OnMouseMove in the dialog class to detect if
>the mouse is over buttons in a dialog. But I found out when the mouse is
>over a button, Windows stops sending WM_MOUSEMOVE message, so I will not be
>able to test if the point is inside the button rectangle.

You should still get WM_SETCURSOR message, so that might be an option.

Alternatively, catch WM_MOUSEMOVE or WM_SETCURSOR in a derived button
class.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq

Joseph M. Newcomer

unread,
Apr 22, 2003, 12:40:02 PM4/22/03
to
Absolutely. It is not that it stops sending messages; it stops sending them to your
dialog, because it is over the button, and by the rules of Windows, the mouse messages go
to the window under the mouse, that is, the button.

What you need to do is subclass the buttons, and use the WM_MOUSEHOVER message in the
subclass. It would be inappropriate to try to do this in the dialog, although it might be
that the WM_MOUSEHOVER handler might GetParent()->SendMessage(...) a user-defined message
to notify the parent that something interesting is happening. But it is better to just
handle this in the button subclass itself.

class CMyButton : public CButton { ... created by ClassWizard...

LRESULT OnMouseHover(WPARAM, LPARAM);
};

in your message map in your .cpp file for the button subclass

ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)

LRESULT CMyButton::OnMouseHover(WPARAM wParam, LPARAM lParam)
{
// wParam has the flags
// LOWORD(lParam) is the x-coordinate of the current position
// HIWORD(lParam) is the y-coordinate of the current position
// coordinates are in client coordinate space
... do your hover thing here...
return 0;
}
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages