简体   繁体   English

Win32 中缺少鼠标移动消息

[英]Missing mouse movement messages in Win32

I'm writing a Win32 OpenGL application for painting where it is critical that all mouse movement is handled.我正在编写一个用于绘制的 Win32 OpenGL 应用程序,其中处理所有鼠标移动至关重要。 As it happens, sometimes the painting operation in my program is not able to perform in real time -- which is fine for me, as long as all mouse events are queued and can be handled later.碰巧的是,有时我的程序中的绘制操作无法实时执行——这对我来说很好,只要所有鼠标事件都排队并且可以稍后处理。 Now I would have thought that this would simply be a matter of calling PeekMessage making sure to process all events, but when I do this, it is apparent that the mouse movements my application receives are not of the same fidelity that as those being displayed by Windows.现在我会认为这只是调用PeekMessage以确保处理所有事件的问题,但是当我这样做时,很明显我的应用程序接收到的鼠标移动与显示的鼠标移动的保真度不同窗户。

Is this a feature of Windows?这是 Windows 的功能吗? Are mouse event dropped when the application is labor intensive?当应用程序是劳动密集型时,鼠标事件是否被丢弃? Or am I missing something?或者我错过了什么? In either case, what can I do to remedy this situation?在这两种情况下,我能做些什么来纠正这种情况? I would like to avoid multi-threading, part of the reason being that, as I understand, Win32 requires the message callback to be in the main thread and I'm not sure about separating the OpenGL-stuff to a different context.我想避免多线程,部分原因是,据我所知,Win32 要求消息回调位于主线程中,我不确定是否将 OpenGL 内容分离到不同的上下文。

And as for code example, I am essentially using the template code in the link below.至于代码示例,我基本上使用了下面链接中的模板代码。 The message I'm checking for is WM_MOUSEMOVE .我正在检查的消息是WM_MOUSEMOVE

http://nehe.gamedev.net/tutorial/creating_an_opengl_window_(win32)/13001/ http://nehe.gamedev.net/tutorial/creating_an_opengl_window_(win32)/13001/

Is this a feature of Windows?这是 Windows 的功能吗? Are mouse event dropped when the application is labor intensive?当应用程序是劳动密集型时,鼠标事件是否被丢弃?

Yes, this is a feature.是的,这是一个功能。 WM_MOUSEMOVE messages are not dropped, they are synthesized . WM_MOUSEMOVE 消息不会被丢弃,它们是合成的 In other words, they are not actually posted to the message queue.换句话说,它们实际上并没有发布到消息队列中。 That wouldn't work very well in practice, a user could generate a great many mouse moves in a second and rapidly fill the message queue to capacity when your program is busy.这在实践中效果不佳,用户可以在一秒钟内生成大量鼠标移动,并在您的程序繁忙时迅速将消息队列填满。

You get a WM_MOUSEMOVE message when the mouse was moved since the last time you called GetMessage().自上次调用 GetMessage() 以来鼠标移动时,您会收到 WM_MOUSEMOVE 消息。 And you get the last known position.你会得到最后一个已知位置。 So the rate at which you get them, and the number of pixels between them, depend directly on how often you call GetMessage().因此,您获取它们的速率以及它们之间的像素数直接取决于您调用 GetMessage() 的频率。

An alternative is to use raw input .另一种方法是使用原始输入

WM_MOUSEMOVE is special in that it isn't queued; WM_MOUSEMOVE的特殊之处在于它不排队; it's automatically generated as needed when the message queue is empty.当消息队列为空时,它会根据需要自动生成。 ( WM_PAINT and WM_TIMER behave the same way.) WM_PAINTWM_TIMER行为方式相同。)

Raymond Chen suggests using GetMouseMovePointsEx if you need additional mouse input data.如果您需要额外的鼠标输入数据, Raymond Chen 建议使用GetMouseMovePointsEx

Additional reading:补充阅读:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM