离开控件时未收到鼠标离开消息 [英] Mouse leave message is not received when it leaves the control

查看:91
本文介绍了离开控件时未收到鼠标离开消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MFC类在Visual C ++中开发一个Outlook栏控件.当前,当鼠标悬停在一个按钮上时,会生成3D外观以显示鼠标当前在该按钮上,并且当我将鼠标从该按钮移动到下一个按钮时,上一个按钮将进入正常状态,而新按钮将变为正常状态鼠标现在已移动,显示3D外观.到现在为止一切都很好.

问题是,当我将鼠标移至Outlook Bar控件中的第一个按钮时,它具有3D效果,但是当我进一步向上移动鼠标使其离开控件的边界时,该按钮仍保留在该3D位置错误,应该恢复其正常位置.

我在when_mouse_move事件处理程序中处理此功能.实际上,当鼠标从第一个按钮移动到主窗口的工具栏时,它既不会接收when_mouse_move消息,也不会接收when_mouse_leave消息来指示我鼠标已超出控件的边界.请帮助我解决此问题.

I am developing an outlook bar control in visual C++ using MFC classes. Currently when the mouse hovers a button, then a 3D look is generated to show that mouse is currently on that button and when i move the mouse from this button to the next, the previous button gets to normal state and the new button over which the mouse has now moved shows a 3D look. Until now things are going fine.

The problem is that when i move the mouse to the first button in the outlook bar control, it gives 3D look which is good, but when i move the mouse further up so that it leaves the boundary of the control, then the button remains in that 3D position which is wrong, instead it should restore its normal position.

I am handling this functionality in the when_mouse_move event handler. Actually when mouse moves from first button to the tool bar of the main window, then it neither receives the when_mouse_move message nor it receives the when_mouse_leave message to indicate me that mouse has passed beyond the boundary of the control. Kindly help me to fix this issue.

推荐答案

Windows不会自动发送WM_MOUSELEAVE消息.当鼠标进入控件时,您需要调用_TrackMouseEvent使其在发生这种情况时通知您:

Windows does not automatically send a WM_MOUSELEAVE message. When the mouse enters the control, you need to call _TrackMouseEvent to get it to notify you when this occurs:

// track the mouse so we know when it leaves our window
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE;
tme.dwHoverTime = 1;
_TrackMouseEvent(&tme);


某些MS Windows控件(例如列表控件头)
由他们自己处理"OnMouseLeave"事件
OnTimer(..)回调(什么窗口或它的一部分在鼠标下?).

也尝试这样做...:)
Some MS Windows controls (for example the list control header)
are handling the "OnMouseLeave" event by their own
OnTimer(..) callbacks (what window or its part is under mouse?).

Try to do it too... :)


这篇关于离开控件时未收到鼠标离开消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆