来自另一个线程的 SendMessage() 调用是否将消息发布到消息队列?

Does a SendMessage() call from another thread posts a message to the message queue?

我读过关于从另一个线程调用 SendMessage() 的两个相互矛盾的概念:

那么哪一个是正确的?

在我看来,SendMessage 的文档相当清楚:

If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message.

SendMessage 发送的消息永远不会放在消息队列中。换句话说,你的第一个要点是完全错误的。

在跨线程发送消息的情况下,它在拥有 window 的线程中分派,通常是通过在接收方线程的消息循环中调用 GetMessage。还有其他功能,例如PeekMessageSendMessage 等,将发送消息。