如何检测鼠标是否在列表视图控件中的项目/子项目上? [英] How can I detect if the mouse is over an item/subitem in a List View control?

查看:51
本文介绍了如何检测鼠标是否在列表视图控件中的项目/子项目上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我四处搜索,但没有找到对我来说合理或似乎与我的具体问题相关的解决方案(即使在 Stack Overflow 上也是如此).

I've searched around and haven't found a solution that sounds reasonable to me or that seems relevant to my specific problem (even here on Stack Overflow).

问题很简单:我需要在列表视图的任何单元格上执行自定义复选框的大部分工作;我只需要检测悬停打开/悬停即可绘制热图像.这些图像被设置为控件的状态图像表,因此我想在悬停和单击时更改子项状态.

The problem is simple: I have most of the work needed to do custom checkboxes on any cell of a list view; I just need to detect hover on/hover off to draw the hot images. These images are set as the control's state image table, so I want to change the subitem state on hovers and clicks.

我尝试使用 NM_HOVER ,但是在完成所有使工作正常的工作之后,它没有任何作用.经过进一步研究,似乎只有在 LVS_EX_TRACKSELECT 开启时才会发布,这是我不想要的;我只想处理悬停,而不选择悬停!

I tried using NM_HOVER, but after doing all the work to get things working it didn't work. Upon further research, it seems this is only issued if LVS_EX_TRACKSELECT is on, which I don't want; I just want to handle hovers, not select on hover!

我调查了使用 NM_HOTTRACK NM_ACTIVATE 的方法,但这只能给我一半的答案:我不知道何时所有项目都不会停止悬停(移至确定最后一个热门商品.

I looked into using NM_HOTTRACK and NM_ACTIVATE, but that would only give me half the answer: I would not know when all items stop being hovered over (to cold-ify the last hot item).

我找到了一些CodeProject项目,该项目使用内部工具提示来做一些古怪的事情.我根本不想接触内部数据结构.

I found some CodeProject project that does wacky things with internal tooltips. I don't want to touch internal data structures at all.

我的列表视图是子类的.我需要Common Controls6.我需要在XP或更高版本上运行(尽管将来也可以使用Vista特定的选项).

My List View is subclassed. I require Common Controls 6. I need to run on XP or newer (though a Vista-specific option is also acceptable for the future).

我在这里有什么选择吗?谢谢.

Do I have any options here? Thanks.

推荐答案

由于具有listview子类,因此您可以查看 WM_MOUSEMOVE 消息以检测鼠标移到控件上.

Since you have the listview subclassed you can watch for WM_MOUSEMOVE messages to detect the mouse moving over the control.

根据您的要求,您可能还希望使用 TrackMouseEvent 来捕获鼠标离开窗口的时间.

Depending on your requirements you may also want to use TrackMouseEvent to catch when the mouse leaves the window.

这篇关于如何检测鼠标是否在列表视图控件中的项目/子项目上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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