MFC CListCtrl 吃鼠标向上事件吗?
除非双击,否则 CListCtrl
似乎不会发送鼠标释放事件。
我尝试从鼠标按下处理程序发送丢失的消息来进行补偿,但这会导致其他不良行为。然后我想我可以通过检查状态在鼠标移动处理程序中发送消息,以便更加准确。然而,这些都是可怕的黑客行为,除了丑陋之外,它们可能无法正常工作于派生控件的每种可能的实现。
如果有人知道为什么没有收到鼠标松开事件,我会很好奇。更重要的是如何使用LVS_OWNERDATA
样式获取CListCtrl
来像其他控件一样发送鼠标松开消息?
编辑:我知道< code>LVN_BEGINDRAG、LVN_BEGINRDRAG
等,但是为了使用这些,我需要阻止 WM_LBUTTONDOWN
, WM_RBUTTONDOWN
和 WM_MOUSEMOVE
转到父窗口或挂接到 CWinAppEx
/CMDIFrameWndEx
的 DragDropManager
code> 这样我就可以为该控件制作一个特殊的一次性案例,以便与现有系统一起使用。
这是因为我有一个中央拖放管理器,它可以通知各种类型的控件何时开始拖动操作、何时结束、取消、更改动画、在自定义消息中传递源和目标的显示对象等。它需要足够灵活,可以根据控制、输入、所选或目标项目的类型、包括 3D 在内的不同控制类型,甚至不同的应用程序等,具有不同的启动方式和不同的操作。
It seems that CListCtrl
doesn't send mouse up events unless there is a double click.
I've attempted sending the missing message from the mouse down handlers to compensate but that causes other undesirable behavior. Then I thought I could send the message within the mouse move handler to be a bit more accurate by checking state. However these are horrible hacks and apart from being ugly they may not work properly for every possible implementation of derived controls.
If anyone knows why mouse up events are not received I'd be curious. More importantly how do I get the CListCtrl
using the LVS_OWNERDATA
style to send mouse up messages like every other control?
EDIT: I am aware of LVN_BEGINDRAG
, LVN_BEGINRDRAG
, etc however in order to use these I would need to prevent WM_LBUTTONDOWN
, WM_RBUTTONDOWN
, and WM_MOUSEMOVE
from going to the parent window or DragDropManager
hooked into CWinAppEx
/CMDIFrameWndEx
so I could make a special one-off case for this control to work with the existing system.
This is because I have a central drag and drop manager which can notify various types of controls when to begin a drag operation, when to end, cancel, change animation, pass display objects for source and target in custom messages, etc. It needs to be flexible enough to have differing way of initiating as well as differing actions depending on the control, the input, the type of items selected or targeted, differing control types including 3D, or even different applications, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
作为参考,这是我所拥有的有效方法,但这是一个可耻的黑客行为。如果没有人能想出比这更好的东西,那就太可悲了。
标题:
实施:
For reference here's what I have that works but it's a shameful hack. If no one can come up with anything better than this that's really sad.
Header:
Implementation:
您不需要这些事件。该控件为您提供所需的一切。
从您的代码中我了解到您想要在列表控件中实现项目的拖放。
与其将一些无论如何都行不通的东西拼凑在一起并诽谤微软,不如以正确的方式去做:
处理 LVN_BEGINDRAG 通知开始拖动操作。
You don't need those events. The control provides you with everything you need.
From your code I gather that you want to implement drag'n'drop of items in the list control.
Instead of hacking together something that won't work anyway and badmouth MS, do it the right way instead:
Handle the LVN_BEGINDRAG notification to start the drag operation.
Stefan的答案可能会为您提供最好的服务...
但是,您可以挂钩CListCtrl的winproc(地狱,在MFC中您可以子类化CListCtrl,提供您自己的虚拟WindowProc()并转发/拦截您想要的任何鼠标消息。
只是 标准 CListCtrl 类。
在运行时使用标准 MFC 子类控制机制来“替换”您希望的任何对话框或窗口上的
You may be best served by Stefan's answer....
However, you could hook the CListCtrl's winproc (hell, in MFC you could just subclass the CListCtrl, provide your own virtual WindowProc() and forward / intercept whatever mouse messages you want.
Just use the standard MFC subclass a control mechanic at runtime to "substitute" your class for the standard CListCtrl on whatever dialog or window you wish.
I assume you know how to do that?
您可以使用 LVS_OWNERDRAWFIXED 样式,它使所有鼠标事件都来找您
You can use LVS_OWNERDRAWFIXED style, it makes all mouse events come to you