在GetMessage循环中未接收WM_COMMAND [英] Not receiving WM_COMMAND in GetMessage loop

查看:216
本文介绍了在GetMessage循环中未接收WM_COMMAND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释为什么我从未在我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆