November 19th, 2004

The various ways of sending a message

There are several variations on the SendMessage function, but some are special cases of others.

The simplest version is SendMessage itself, which sends a message and waits indefinitely for the response.

The next level up is SendMessageTimeout which sends a message and waits for the response or until a certain amount of time has elapsed. SendMessage is just SendMessageTimeout with an INFINITE timeout.

Another version of SendMessage is SendNotifyMessage, which is like SendMessage except that it doesn’t wait for the response. It returns immediately and ignores the result produced by the receiving window.

The last SendMessage-style functions is SendMessageCallback. This sends a message and then returns immediately. When the recipient finally returns a response, the callback is called.

SendNotifyMessage is SendMessageCallback with a callback that does nothing.

That’s how the four message-sending functions fit together.

Bonus remark: If you use any of the above send-type functions to send a message to a window that belongs to the sending thread, the call is made synchronously.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.