Mouse Move Capture (Mouse leave & Mouse Enter)

天涯浪子 提交于 2020-03-22 09:51:02

问题


Hi i have three controls (CButtton) in my application,whenever mouse move over a control,i want to capture when mouse enters on which control in a window and when it leaves and i have to change the caption of a button control.

Thanks in Advance


回答1:


There is no windows message/event that indicates 'mouse enter' or 'mouse leave'. However this can be achieved by handling the 'MouseMove' message for your control and capturing the mouse input to check if the point is inside the control area. Release the capture if the point is out of the control area.

for sample code check here.




回答2:


@Hemant:

You are wrong. There are messages for mouse leave and mouse hover, defined in WinUser.h

#if((_WIN32_WINNT >= 0x0400) || (WINVER >= 0x0500))
#define WM_MOUSEHOVER                   0x02A1
#define WM_MOUSELEAVE                   0x02A3
#endif
#if(WINVER >= 0x0500)
#define WM_NCMOUSEHOVER                 0x02A0
#define WM_NCMOUSELEAVE                 0x02A2
#endif /* WINVER >= 0x0500 */

Documentation:

WM_MOUSEHOVER message

WM_MOUSELEAVE message

And you can handle it with a message-mapping like:

ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)


来源:https://stackoverflow.com/questions/3287224/mouse-move-capture-mouse-leave-mouse-enter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!