Win32 Api WM_MOUSEMOVE 快速移动鼠标
我通过 win api 创建了一个小窗口。该窗口是另一个线程窗口的子窗口。
我希望允许用户通过按下右键移动鼠标来移动我的窗口。当我以正常速度移动鼠标时,我的窗口移动没有问题。但是当我移动得很快时,窗口会收到一些非常奇怪的消息。例如,
P WM_MOUSEMOVE fwKeys:MK_BUTTON xPos:-32703 yPos:9
如您所见,xPos 下降到 -32000。当我快速移动鼠标后,它几乎立即发生。我不知道Windows如何向我发送这样的消息。
为什么可以发送该消息以及如何修复它?
我正在使用 SetCaption 函数,因此即使鼠标停留在外面,我的窗口也会收到消息。
更新。解决了。问题出在我固有的数学基础上。从 lParam 获取 hi 和 lowword 是不正确的。
I have created a small window by win api. This window is a child to the window of another thread.
I want allow user to move my window by moving mouse with presed right button. When I move my mouse in normal speed my window moves without problem. But when I move very quick some very strange messages recieved by window. For example,
P WM_MOUSEMOVE fwKeys:MK_BUTTON xPos:-32703 yPos:9
As you see the xPos drops down to a -32000. It happens almost instantly after I move my mouse quick. I have no idea how windows can send me such a message.
Why that message could be sended and how to fix it?
I am using a SetCaption function, so my window recievs messages even if mouse stays outside.
Upd. Solved. The problem was in my inherent maths. Getting hi and lowword from lParam wasn't proper.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在实现拖动支持时遇到了同样的问题,按下左键时用鼠标在屏幕中间快速画小圆圈,生成一些超出范围的位置(例如 -32000 或 -64000,尽管正确处理了 lParam 坐标转换)。这对我来说似乎是一个错误,所以我通过将 x 和 y 裁剪为当前屏幕尺寸(以像素为单位)来解决这个问题,并允许负值降至负数屏幕尺寸框。
这是为了更好地理解而摘录的代码(用 Red/System):
这为我解决了。
I had the same issue while implementing dragging support, making rapid small circles in the middle of the screen with the mouse while left button is pressed, generates some out of range positions (like -32000 or -64000, despite proper handling of the lParam coordinates conversion). This looked like a bug to me, so I worked around it by clipping
x
andy
to current screen size in pixels for the max values and allowing negative values down to a negative screen size box.This is a code extract for better comprehension (written in Red/System):
That solved it for me.