Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Send Message and Post Message and how these relate to C# ,WPF and Pure windows programming?

Tags:

c#

wpf

winapi

What is the difference between Send Message and Post Message ( in terms of pure windows programming) and how these relate to C# ,WPF and Pure windows programming?

I am new to Threading and all related stuff so please excuse me for obvious quesiton . I need to dig out the externals of Threading .. Please let me know the links that help me to build my concept from win32 programming to WPF.

I need to underderstand from Post message to Afx ( call to start a new thread ) to delegate Invok/Begin Invoke to Dispatcher.

like image 627
user407269 Avatar asked Jul 31 '10 03:07

user407269


People also ask

What is the difference between SendMessage and PostMessage?

SendMessage: Sends a message and waits until the procedure which is responsible for the message finishes and returns. PostMessage: Sends a message to the message queue and returns immediately.

What is SendMessage?

Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message. To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function.

What is PostMessage in MFC?

Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.


1 Answers

PostMessage (in "pure windows programming", aka win32 API) is asynchronous, i.e., to quote the docs:

Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.

To post a message in the message queue associated with a thread, use the PostThreadMessage function.

SendMessage is synchronous, that is, again quoting:

Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.

To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.

A good tutorial on these two functions and their use is here.

The connection to WPF is discussed in this SO question.

like image 106
Alex Martelli Avatar answered Sep 22 '22 04:09

Alex Martelli