有没有像 PeekMessage 这样不处理消息的函数?
我试图无意中调用
PeekMessage(&msg, 0, WM_KEYDOWN, WM_KEYUP, PM_NOREMOVE | PM_NOYIELD);
,而 Windows Vista 64 在 PeekMessage 调用中正在处理消息。 结果是我将重新进入我的绘制调用以及各种其他代码。
在我们的应用程序中,绘画可能需要几秒钟的时间,因此我们添加了 PeekMessage 调用来查看用户是否按下了某个键,这样我们就可以中断该绘画并启动下一个绘画。 我们几乎没有意识到 Windows 可以开始处理我们的消息。 将真正的绘画工作放在单独的线程中将是一次重大重构...我们试图查看是否按下了特定的键,或者是否旋转了鼠标滚轮或单击了鼠标按钮,以中断渲染。
我尝试过专门添加代码来防止重新进入,然后将绘制消息重新注入队列等。这一切都非常混乱,并且在某些情况下它不能很好地工作。
我可以在 PeekMessage 调用中添加一些标志吗? 我在 MSDN 上的文档中没有看到任何新内容。 我确实需要一个不处理消息的 PeekMessage
。 帮助!
I'm trying to innocently call
PeekMessage(&msg, 0, WM_KEYDOWN, WM_KEYUP, PM_NOREMOVE | PM_NOYIELD);
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.
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.
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许我错过了显而易见的事情,但是 规范非常冗长它会这样做:
...
Perhaps I'm missing the obvious, but the spec is pretty verbose that it will do so:
...
GetQueueStatus 是检查是否有可用消息的最快方法。 它只会检查几个标志,并且只需要 1 个参数,而 peekmessage 需要 5 个参数。 如果有可用消息,它会给出快速提示,但不会以任何方式处理该消息。
GetQueueStatus 和 GetInputStatus 是相关函数。
GetQueueStatus is the fastest way to check if there are available messages. It will only check a few flags and takes only 1 parameter compared to 5 parameters of peekmessage. It will give a quick hint if there are available messages, it will not process the message in any way.
GetQueueStatus and GetInputStatus are related functions.
我认为这就是 PeekMessage 应该做的。 它和 GetMessage 之间的唯一区别是GetMessage 会阻塞,直到消息到达,而 PeekMessage 将根据是否找到与过滤器匹配的消息返回 TRUE 或 FALSE。 如果找到消息,它仍然会处理消息。
I think this is what PeekMessage is supposed to do. The only difference between it and GetMessage is that GetMessage blocks until a message arrives, where as PeekMessage will return TRUE or FALSE depending on whether a message matching the filter was found. It will still process the messages if they are found.
PeekMessage 处理消息,因为这就是 PeekMessage 的作用。
也许它的命名很糟糕,但 PeekMessage 确实会从队列中删除消息(如果有可用的消息)。
PeekMessage processes messages because that's what PeekMessage does.
Maybe it's badly named, but PeekMessage do remove the message from the queue if there are any available.