我最近遇到了一种情况,我想在 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/