C#低级鼠标钩子和表单事件处理

编程入门 行业动态 更新时间:2024-10-27 22:19:26
本文介绍了C#低级鼠标钩子和表单事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的是2010年VS其中包含2个按钮,启动和停止生成一个简单的表格。 开始触发WH_MOUSE_LL使用SetWindowsHookEx函数,并停止停止钩。 挂钩工作正常,我奶源与双击替换鼠标中键点击,我唯一的问题是点击最小化形式/最大化/关闭按钮,似乎有某种事件竞赛挂钩和事件由上述按钮叫之间。它反映的事实是,当你按了它不断被逼了一回它完成之前的一个按钮的行动(例如最小化的形式)。 当我右键单击窗体,然后选择它响应这些行动一出,立即相同的事情会发生在我停下挂钩,按上述按钮之一。 具有人遇到这样的行为?

I'm using a simple form generated by VS 2010 which contains 2 buttons, start and stop. Start triggers WH_MOUSE_LL using SetWindowsHookEx, and stop stops the hook. The hook works fine and I mange to "replace" middle mouse button click with double click, the only problem I have is clicking on Minimize/Maximize/Close buttons of the form, it seems that there is some sort of "event race" between the hook and events called by buttons mentioned above. It reflects on the fact that when you press one of those buttons it keeps being "pressed" for a while before it completes it's action (e.g. form minimizes). When I right click the form and select one of those actions it responds immediately same thing goes when I stop the hook and press one of the buttons mentioned above. Have anyone encountered such behavior ?

推荐答案

我以前都经历过这一点。我不知道来的确切原因,但我一直通过监听当鼠标进入和离开形式的客户区被触发的事件,窗口,无论解决了这个问题。您可以使用这些事件挂钩和脱钩鼠标,然后你会得到正常的行为。

I have experienced this before as well. I'm not sure as to the exact cause, but I have always solved the problem by listening for events that are fired when the mouse enters and leaves the client area of the form, window, whatever. You can use those events to hook and unhook the mouse, and then you will get the normal behaviour.

更多推荐

C#低级鼠标钩子和表单事件处理

本文发布于:2023-11-08 10:49:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569175.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:鼠标   钩子   表单   低级   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!