问题描述
我想无辜地打电话
PeekMessage(&msg, 0, WM_KEYDOWN, WM_KEYUP, PM_NOREMOVE | PM_NOYIELD);
和 Windows Vista 64 在 PeekMessage 调用中处理消息.结果是我将重新进入我的绘画调用和各种其他代码.
and Windows Vista 64, in the PeekMessage call, is processing messages. The result is that I'm going re-entrant on my paint call, and all sorts of other code.
在我们的应用程序中绘制可能需要几秒钟,因此我们添加了 PeekMessage 调用以查看用户是否按下了键,因此我们可以中断该绘制并开始下一个绘制.我们几乎没有意识到 Windows 可以开始处理我们的消息.将真正的绘画工作放在一个单独的线程中将是一个重大的重构......我们正在尝试查看是否按下了特定的键,或者是否旋转了鼠标滚轮或单击了鼠标按钮,以中断渲染.
Painting can take seconds in our application, so we added the PeekMessage call to see if the user hit a key, so we could interrupt that painting and start up the next one. Little did we realize that Windows could start processing messages on us. It'd be a major refactoring to put the real work of painting in a separate thread... We're trying to see if specific keys were pressed, or if the mouse wheel rotated or mouse buttons were clicked, to interrupt rendering.
我尝试过专门添加代码来防止重入,然后将绘制消息重新注入队列等.这一切都非常麻烦,并且在某些情况下效果不佳.
I've tried adding code specifically to prevent re-entrancy, and then re-injecting paint messages into the queue, etc. It's all very kludgey, and there are cases where it doesn't work well.
有什么标志可以添加到 PeekMessage 调用中吗?我在 MSDN 上的文档中没有看到任何新内容.我真的需要一个不处理消息的 PeekMessage
.帮助!
Is there some flag I could add to the PeekMessage call? I didn't see anything new in the documentation on MSDN. I really need a PeekMessage
that doesn't process messages. Help!
推荐答案
也许我错过了明显的,但是 规范非常冗长,它会这样做:
Perhaps I'm missing the obvious, but the spec is pretty verbose that it will do so:
PeekMessage 函数 调度传入发送的消息,检查已发布的线程消息队列消息,并检索消息(如果任何存在).
...
在这次通话中,系统提供待处理的非排队消息,即发送到 Windows 拥有的消息使用 SendMessage 调用线程,发送消息回调,SendMessageTimeout,或SendNotifyMessage 函数.那么匹配的第一个排队消息检索指定的过滤器.该系统也可以处理内部事件.如果没有指定过滤器,消息在以下顺序:
- 已发送消息
- 发布的消息
- 输入(硬件)消息和系统内部事件
- (再次)发送消息
- WM_PAINT 消息
- WM_TIMER 条消息
检索输入消息之前发布消息,使用 wMsgFilterMin和 wMsgFilterMax 参数.
To retrieve input messages before posted messages, use the wMsgFilterMin and wMsgFilterMax parameters.
这篇关于有没有像 PeekMessage 这样不处理消息的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!