不同线程中的postmessage和message loop

postmessage and message loop in different thread

我正在阅读其他人的代码并且他们的代码可以正常工作。我只是对 postmessage 和他们使用的消息循环感到有点困惑

#define MESSAGE XXX //some number
BEGIN_MESSAGE_MAP(myClass, CDialog)
//...
ON_THREAD_MESSAGE(...)
END_MESSAGE_MAP()
... myClass::funcA(...)
{
    static HANDLE t = createThread(...., funcB,....)
    .....
    postmessage(MESSAGE)

}

... myClass::funcB(...)
{
    ....
    while(...)
    {
        TranslateMessage(&msg);
        dispatchMessage(&msg);
    }

}

代码看起来像那样,但稍作修改

根据 MSDN _In_opt_ 当 PostMessage 的 HWND hWnd 设置为 null

The function behaves like a call to PostThreadMessage with the dwThreadId parameter set to the identifier of the current thread.

这让我很困惑。看来主线程创建的t线程真的收到了msg?谁能解释一下?

顺便说一句,我是 mfc 的新手,这是我的第一个 post,如果我有任何误解,请告诉我

您似乎在调用 CWnd::PostMessage 函数,而不是 API PostMessage 函数。因此,该调用使用其 HWND 成员向 myClass 对话框发布一条消息,该消息将在进行调用的同一线程中接收。