在GetMessage循环中未接收WM_COMMAND [英] Not receiving WM_COMMAND in GetMessage loop
问题描述
有人可以解释为什么我从未在我的GetMessage循环中收到 WM_COMMAND
消息?
我已经选中,WndProc正在接收 WM_COMMAND
消息,所以我很困惑为什么这不工作。
Could someone explain why I never receive a WM_COMMAND
message in my GetMessage loop?
I've checked and the WndProc is receiving the WM_COMMAND
message, so i'm very confused why this doesn't work.
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_COMMAND)
{
// This never happens:
MessageBox(NULL, "WM_COMMAND", "WM_COMMAND", MB_OK);
}
}
操作系统:Windows 8
OS: Windows 8
推荐答案
因为WM_COMMAND与SendMessage()一起发送。其中直接调用窗口过程。只有使用PostMessage()发布的消息才会添加到队列中,并由GetMessage()检索。
Because WM_COMMAND is sent with SendMessage(). Which directly calls the window procedure. Only messages posted with PostMessage() get added to the queue and are retrieved by GetMessage().
您可以在像Spy ++这样的实用程序中查看此消息与P发送的消息和与S发送的消息。
You can see this back in a utility like Spy++, it annotates messages that are posted with P and messages that are sent with S.
这篇关于在GetMessage循环中未接收WM_COMMAND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!