C# 中的 Win api。 MouseMove 事件无法捕获快速移动
我用 C# 中的 WinApi 函数创建了一个无边框的小窗口。我想在按下鼠标右键时移动此窗口。我试图通过任意化 WM_MOUSEMOVE 事件来捕获鼠标偏移。它似乎有效,我可以按住鼠标右键移动窗口。
但是当我移动鼠标太快时,我就会失去对窗口的控制。这是因为我的窗口太小,如果鼠标很快离开窗口,它就不会再收到 WM_MOUSEMOVE 消息,并且我无法计算 MouseOffset 来移动我的窗口。
那么,我该如何解决这个问题?
I have created a small Window without border by WinApi functions in C#. I want to move this window when right mouse button is pressed. I am trying to catch a mouse offset by anylizing WM_MOUSEMOVE event. It seems to work and i can move my window holding Right Mouse Button.
But I am loosing control of the window when i move my mouse too fast. That's because my Window is too small and if mouse leaves window very quick it doesn'n recieve WM_MOUSEMOVE messages anymore and i can't calculate a MouseOffset to move my Window.
So, How I can fix that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要调用 SetCapture 来告诉 Windows 您的 hwnd 需要所有事件,即使鼠标实际上并未位于窗口上方。 http://msdn.microsoft。 com/en-us/library/windows/desktop/ms646262(v=vs.85).aspx
You need to call SetCapture to tell Windows that your hwnd wants all the events even when the mouse isn't physically over the window. http://msdn.microsoft.com/en-us/library/windows/desktop/ms646262(v=vs.85).aspx
您可以告诉 Windows 用户实际上将鼠标放在标题栏上,它会自动为您处理其余的事情。
You can tell Windows that the user actually moused down on the title bar and it will handle the rest automatically for you.