包装的控件设置了捕获后,如何接收鼠标事件? [英] How can I receive mouse events when a wrapped control has set capture?

查看:130
本文介绍了包装的控件设置了捕获后,如何接收鼠标事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在按下修饰键(Shift或Control)的情况下单击时,我的WndProc没有看到鼠标向上的通知.我看到它们没有修饰键,并且看到有修饰键的鼠标向下通知.

My WndProc isn't seeing mouse-up notifications when I click with a modifier key (shift or control) pressed. I see them without the modifier key, and I see mouse-down notifications with the modifier keys.

我试图跟踪我未编写的组件中的用户操作,因此我正在使用Windows Forms NativeWindow包装器(包装该组件)从WndProc()方法获取Windows消息.

I'm trying to track user actions in a component I didn't write, so I'm using the Windows Forms NativeWindow wrapper (wrapping the component) to get Windows messages from the WndProc() method.

我已经尝试跟踪我收到的通知,而我看到的唯一线索是WM_CAPTURECHANGED.收到WM_LBUTTONDOWN消息时,我曾尝试调用SetCapture,但这无济于事.

I've tried tracking the notifications I do get, and I the only clue I see is WM_CAPTURECHANGED. I've tried calling SetCapture when I receive the WM_LBUTTONDOWN message, but it doesn't help.

不带修饰符(跳过油漆,计时器和NCHITTEST消息):

Without modifier (skipping paint, timer and NCHITTEST messages):

WM_PARENTNOTIFY
WM_MOUSEACTIVATE
WM_MOUSEACTIVATE
WM_SETCURSOR
WM_LBUTTONDOWN
WM_SETCURSOR
WM_MOUSEMOVE
WM_SETCURSOR
WM_LBUTTONUP

带有修饰符(跳过油漆,计时器和NCHITTEST消息):

With modifier (skipping paint, timer and NCHITTEST messages):

WM_KEYDOWN
WM_PARENTNOTIFY
WM_MOUSEACTIVATE
WM_MOUSEACTIVATE
WM_SETCURSOR
WM_LBUTTONDOWN
WM_SETCURSOR (repeats)
WM_KEYDOWN (repeats)
WM_KEYUP

如果我长时间按住鼠标按钮,通常可以收到WM_LBUTTONUP通知,但是应该可以使其响应速度更快.

If I hold the mouse button down for a long time, I can usually get a WM_LBUTTONUP notification, but it should be possible to make it more responsive..

在释放鼠标按钮之前,我尝试按住Control键单击感兴趣的组件,然后将光标移到其中,然后收到WM_LBUTTONUP通知,因此看起来该组件正在捕获鼠标.鼠标向下.当另一个窗口捕获了鼠标时,有什么方法可以接收该通知?

I've tried control-clicking outside of the component of interest and moving the cursor into it before releasing the mouse button, and then I do get a WM_LBUTTONUP notification, so it looks like the component is capturing the mouse on mouse-down. Is there any way to receive that notification when another window has captured the mouse?

谢谢.

推荐答案

通常,当在(本机)Windows控件上单击鼠标时,会输入某种模式跟踪循环来管理拖动"操作.在模态循环的持续时间内,直接从消息队列中提取消息并进行处理-鼠标上移通知将是模态循环的终止条件之一,因此通常在不进行分派的情况下将其消耗掉.

Frequently, when the mouse is clicked down on a (native) windows control, some kind of modal tracking loop is entered to manage the "drag" operation. During the duration of the modal loop messages are directly extracted from the message queue and processed - the mouse up notification would be one of the terminating conditions for the modal loop and thus typically consumed without being dispatched.

您可以单击桌面上的其他位置,将鼠标移到窗口上方并释放并查看单击吗?这将表明某种形式的模式代码正在鼠标按下消息上触发.

Can you click elsewhere on the desktop, move the mouse over the window and release and see the click? That would indicate some kind of modal code is being triggered on mouse-down messages.

我可以想到四种解决此问题的方法.

I can think of four ways you can possibly get around this problem.

  • 找出控件支持哪种拖动操作-并将其禁用.希望如果内置的WindowProc知道不允许模态拖动,则不会进入模态循环.
  • 防止WindowProc发现模式拖动:即拦截并不要将任何WM_LBUTTONDOWN消息传递给链中的下一个Windowproc.
  • 使用SetWindowsHookEx安装消息挂钩.

所有这些解决方案都是Windows API.不知道它们如何在托管环境中翻译.

All these solutions are very windows API. No idea how they translate in the managed environment.

这篇关于包装的控件设置了捕获后,如何接收鼠标事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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