user4344762
user4344762

Reputation:

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

I have read two contradictory concepts about calling SendMessage() from another thread:

So which one is correct?

Upvotes: 2

Views: 2123

Answers (1)

David Heffernan
David Heffernan

Reputation: 612964

The documentation for SendMessage is, in my view, reasonably clear:

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.

Messages sent with SendMessage are never placed on the message queue. In other words, your first bullet point is completely false.

In the case where a message is sent cross-thread, it is dispatched in the thread that owns the window, typically by calls to GetMessage in the recipient thread's message loop. There are other functions, e.g. PeekMessage, SendMessage etc., that will dispatch messages.

Upvotes: 5

Related Questions