Can SendMessage come back earlier if the receiving stream starts pumping messages?

How exactly do Windows decide to return SendMessage, that is, how does it decide that the receiving stream has finished processing the sent message?

Detailed scenario: I have thread A using SendMessage to send a thread to thread B. Obviously, SendMessage does not return until thread B has finished processing the message. A dialog box appears in stream B and message transfer starts. In my script, there is a WM_KILLFOCUS message in the queue, which is pumped by stream B. This is the result of the WM_COMMAND message in stream B. Thread B passes this WM_COMMAND message to the default window. When this happens, SendMessage will return to thread A, although the original message has not finished processing! What's happening? By default, the proc window seems to obfuscate the windows, thinking that the original sent message was complete.

So, are there any well-known scenarios in which forwarding messages and invoking a window window by default can return SendMessage?

Thanks! Phil

+3
source share
4 answers

While message processing has begun, WindowProc processing of the interthread message may call ReplyMessage to allow the calling thread to continue while processing continues.

+4
source

Since SendMessage has a return value, it is always after processing the message.

PostMessage , on the other hand, will not wait for message processing.

From MSDN to SendMessage :

The SendMessage function calls the window procedure for the specified window and the window procedure will not return the processed message.

There is no case when it will be returned before processing the message.

+2
source

From MSDN, it sounds like the problem may be that displaying a dialog box on stream B can cause deadlocks. See Message Alerts .


Perhaps this is due to the fact that the message received by stream A is an unreserved message. From MSDN:

However, the send stream will process incoming unreserved messages in anticipation of the message being processed. To prevent this, use SendMessageTimeout with the SMTO_BLOCK to set. For more information about instant messages, see Unexpected Messages .

+1
source

It sounds like your original SendMessage has NOT returned, but instead of processing the sent message, WindowProc was called in thread A. There is no requirement that the message handler should refrain from calling SendMessage in response to receiving the message.

You should be able to see the original SendMessage call on your call stack in the place where you get the WM_COMMAND sent in response to the focus change message.

0
source

Source: https://habr.com/ru/post/1300946/


All Articles