Win32:在该示例中,是什么导致我的消息循环无法正常工作?
我最近遇到了一种情况,我想在 Win32 中使用非模式对话框。
Win32:工具栏对话框似乎永远不会获得焦点并导致主窗口处理缓慢!?
我发现这是我的消息循环:
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...
}
工作完美!
I recently ran into a situation where I wanted to use a modeless dialog in Win32's.
Win32: Toolbar dialog seems to never get focus and causes the main window to process slow!?
And I figured out that this was my message loop:
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...
}
}
In fact, this message loop works fine as long as I don't have any modeless dialog, as it works perfectly fine with modal dialogs, since they process their own message loop. My modeless dialog worked flawlessly when I replaced the hWnd
instance for NULL
. I just don't get the difference, except that it seems that I get the messages not for one particularly window.
Can someone explain what is making this message loop work inccorectly?
As this one:
while (GetMessage(&Msg, NULL, 0, 0) > 0) {
// Processing messages here...
}
works flawlessly!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
区别非常明显:您在
GetMessage
中指定了HWND
。因此,您不会处理任何其他窗口(包括工具栏)的任何消息。请参阅 GetMessagethe difference is pretty obvious: you specified a
HWND
inGetMessage
. So, you are not processing any messages for any other windows, your toolbar included. See the docs for GetMessage