c - Win32 : What is making my message loop work incorrectly in that example?

标签 c message winapi windows-messages message-loop

我最近遇到了一种情况,我想在 Win32 中使用无模式对话框。

Win32: Toolbar dialog seems to never get focus and causes the main window to process slow!?

我发现这是我的消息循环:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
    // Doing required stuff here...

    while (GetMessage(&Msg, hWnd, 0, 0) > 0) {
        // Processing messages here...
    }
}

事实上,只要我没有任何无模式对话框,这个消息循环就可以正常工作,因为它与模式对话框一起工作得很好,因为它们处理自己的消息循环。当我将 hWnd 实例替换为 NULL 时,我的无模式对话框运行完美。我只是不明白其中的区别,只是我收到的消息似乎不是针对某个特定窗口的。

谁能解释一下是什么导致这个消息循环工作不正常?

作为这个:

while (GetMessage(&Msg, NULL, 0, 0) > 0) {
    // Processing messages here...
}

完美运行!

最佳答案

区别非常明显:您在 GetMessage 中指定了一个 HWND。因此,您没有处理任何其他窗口的任何消息,包括您的工具栏。请参阅 GetMessage 的文档

关于c - Win32 : What is making my message loop work incorrectly in that example?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4465311/

相关文章:

c++ - eclipse Debug模式下的 GDB 找不到 stdlib/rand.c

WCF 跟踪和消息日志记录 - 跟踪级别警告

c - Visual Studio 2013 : Access violation when attempt to change value of variable obtained from LockResource()

c++ - 每个显示器 DPI 感知 : black window glitch with NVIDIA Optimus

正确释放指向链表的指针

c - C, "void main (int argc, char *argv[0])"是什么,注意 argv 中的零

c - 使用缓冲读取实现 getchar

git filter-branch --msg-filter 重写推送的提交消息

java - 从 Java 移动应用程序连接到 Web 服务以读取消息

java - 如何用JNI和C检测鼠标点击?