如何处理 Microsoft Visual C++ ( MFC ) 中特定控件的鼠标悬停事件?

How to handle mouse hover event for specific control in Microsoft visual C++ ( MFC )?(如何处理 Microsoft Visual C++ ( MFC ) 中特定控件的鼠标悬停事件?)
本文介绍了如何处理 Microsoft Visual C++ ( MFC ) 中特定控件的鼠标悬停事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要处理鼠标悬停事件来更改按钮的背景.使用 MFC 类向导,我在该项目的事件列表中找不到鼠标悬停条目.我尝试使用 PreTranslateMessage,但它不起作用.我该如何处理该事件?

In my application I need to handle mouse hover event to change the background of a button. Using the MFC class wizard, I couldn't find a mouse hover entry in the list of events for that item. I tried using PreTranslateMessage, but it doesn't work. How can I handle that event?

推荐答案

默认不生成鼠标悬停事件.您必须通过调用 TrackMouseEvent 来请求它们正确填充 TRACKMOUSEEVENT 结构:

Mouse hover events aren't generated by default. You have to request them by calling TrackMouseEvent with a properly populated TRACKMOUSEEVENT structure:

TRACKMOUSEEVENT tme = { 0 };
tme.cbSize = sizeof( tme );
tme.dwFlags = TME_HOVER;
tme.hwndTrack = myButton;
tme.dwHoverTime = myHoverTime;  // HOVER_DEFAULT, or the hover timeout in milliseconds.
::TrackMouseEvent( &tme );

然后系统将生成 WM_MOUSEHOVER 消息如果鼠标悬停在 myButtonmyHoverTime 毫秒.

The system will then generate WM_MOUSEHOVER messages if the mouse hovers over myButton for myHoverTime milliseconds.

由于 WM_MOUSEHOVER 消息已发布到请求鼠标悬停消息的窗口,因此您必须派生一个自定义按钮控件,并在其消息映射中包含适当的条目.特别是,您必须使用 ON_WM_MOUSEHOVER() 宏并实现 afx_msg void OnMouseHover(UINT, CPoint)(参见 WM_ 消息处理程序:L - M 供参考).

Since the WM_MOUSEHOVER message is posted to the window that requested mouse hover messages, you will have to derive a custom button control, with appropriate entries in its message map. In particular, you will have to use the ON_WM_MOUSEHOVER() macro and implement afx_msg void OnMouseHover(UINT, CPoint) (see WM_ Message Handlers: L - M for reference).

这篇关于如何处理 Microsoft Visual C++ ( MFC ) 中特定控件的鼠标悬停事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)