MFC 对话框列表视图上的鼠标移动事件
我创建了一个对话框。我在其中创建了两个列表视图。 我为列表视图创建了一个子类。 我想知道鼠标在哪里,我的意思是在哪个列表视图上。 之后,我将使用 CListCtrl::HitTest() 查找列表视图的索引。
现在我使用 HitTest 获取索引,但鼠标移动对于两个列表视图都很常见。 那么我如何区分鼠标移动事件中的列表视图。
最后,我将根据列表视图和该列表视图的索引创建工具提示。
I have created a dialogbox. On which I have created two list views.
I have created a sub class for list view.
I wanted to know where is mouse, I mean on which list view.
After that I will find the index of list view using CListCtrl::HitTest().
Now I am getting the index using HitTest but Mouse move is common for both List view.
So how I can distinguish the list view in mouse move event.
Finally I am going to create the tooltip according to list view and index of that list view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CListCtrl 继承自 CWnd。您可以通过实施 CWnd: 来获取鼠标指针坐标: OnMouseMove。您主要有两个选择:
无论您选择什么解决方案,请记住,OnMouseMove 会被频繁调用,并且该函数的实现必须非常轻,否则它将加载计算机资源并且应用程序将滞后。
哈特哈,
JP。
CListCtrl inherits form CWnd. You can get the mouse pointers coordinates implementing CWnd::OnMouseMove. You mainly have two options:
Whatever solution you pick keep in mind that OnMouseMove is called very often and the implementation of the function must be very light otherwise it will load the computers resources and the application will lag.
HTH,
JP.
如果您真正想要的只是在鼠标悬停在您拥有的某个控件上时显示工具提示,则无需在命中测试、鼠标坐标等方面搞得那么麻烦。只需使用 Windows 的内置机制即可。
假设您的对话框类是两个列表视图的父级:
从对话框的
OnCreate()
调用EnableToolTips()
。向消息映射添加处理程序,例如:
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnTtnNeedText)
。在对话框类中实现
OnTtnNeedText()
。示例:差不多就是这样。有关详细信息,请参阅此内容: 文章
If all you really want is to display a tool-tip whenever the mouse hovers over some control you have, there's no need getting your hands so dirty with hit-tests, mouse coordinates, etc. Just use windows' built-in mechanism for that.
Assuming that your dialog class is the parent of the two list views:
From the dialog's
OnCreate()
callEnableToolTips()
.Add a handler to the message map, such as:
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnTtnNeedText)
.Implement
OnTtnNeedText()
in the dialog class. Example:And that's more or less it. Refer to this for more information: article