winapi - 为什么 PeekMessage 总是返回 TRUE?

标签 winapi peekmessage

        // Main message loop

        MSG msg;
        ZeroMemory( &msg, sizeof( msg ) );
        while(msg.message!=WM_QUIT)
        {

            if(PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
            {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
            else
            {
                Render();
            }
        }

“渲染”函数尚未执行

最佳答案

PeekMessage文档中关于返回值的说明如下:

If a message is available, the return value is nonzero.

If no messages are available, the return value is zero.

当消息队列为空时,确实会返回零,即FALSE。因此结论是消息队列永远不会为空。最可能的解释是,您在 DispatchMessage 中处理的消息之一会导致将同一消息发布到队列中。

关于winapi - 为什么 PeekMessage 总是返回 TRUE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9759001/

相关文章:

C++ 从注册表中获取 Windows 产品 ID

c++ - 我的设备通过 USB 连接后触发 exe

windows - 有没有像PeekMessage这样不处理消息的函数?

c++ - GetMessage/PeekMessage - 删除消息队列中的所有消息

c++ - code::blocks 出现奇怪的编译器错误

c++ - GetProcessAffinityMask 返回空进程关联

c - 如何从 Windows PE 获取脱机 Windows 驱动器盘符?

c++ - 编译器找不到结构,我应该包括什么

delphi - 为什么要在 getmessage 之前先 peekmessage?