Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what is PostMessage ? how can we use from an thread ? i went through some documents but it is not clear enough for me to understand so guys pls give inputs regarding this.....Thanx in Advance
Posted
Comments
Code-o-mat 27-Jun-12 8:50am    
What part of it do you not understand? If all we know is that you want to know what PostMessage is, i doubt we can give you a better answer than any documentation, like MSDN can.

It is one of the oddities of Windows Naming that "SendMessage()", unlike TCP/IP "send()", is not a "fire and forget" message passing mechanism.

SendMessage() is an immediate dispatch to the target window's (HWND) message handling and does not return until the message processing is complete and may return the result of that message processing (like getting a controls value). All of the processing for the message is done on your stack and in your thread's context.

Since only the thread that "owns" (read : created) the control can manipulate it, it is not possible for one thread (e.g., a "worker thread") to directly manipulate a control "owned" by another thread (e.g., the "GUI thread") so "SendMessage()" is not an appropriate mechanism.

Hence, "PostMessage()" is the mechanism to send standard Window Control messages from a "non-GUI" thread to the controls. Custom or User Defined messages are also possible to create a way to "trigger GUI actions" from other threads.

Note that neither "SendMessage()" nor "PostMessage()" are meant for general purpose message passing as the destination (HWND) and data values (WPARAM, LPARAM) are very restricted in size and format. If you want general message / interprocess commmunication capability, post a more specific question as there are several options, some better than others.
 
Share this answer
 
Comments
Espen Harlinn 27-Jun-12 9:52am    
A fine reply :-D
Sergey Alexandrovich Kryukov 27-Jun-12 12:41pm    
Good explanation, a 5.
--SA
Messaging is the basic way within the MS framework to get information between windows (of course, you don't have to necessarily be a window to get/send a message).

The two basic methods, SendMessage() and PostMessage() are similar (in prototype) but very different in behavior. SendMessage() is a synchronous message sender, where the calling method waits for the message to be sent and processed by the receiver and the receiver to return. In contrast, PostMessage() is asynchronous, in which case the sender sends the message and DOES NOT wait for a return from the receiver. Each method has it's appropriate uses, so be careful to choose the correct one.

To add to the mix, there is also PostThreadMessage(), and asynchronous call that uses a thread handle rather than a window handle to post messages to.
 
Share this answer
 
v2
Comments
Espen Harlinn 27-Jun-12 9:52am    
A fine reply :-D
Albert Holguin 27-Jun-12 10:09am    
Thank you Espen.
Rajeev Jayaram 27-Jun-12 10:09am    
Good answer!
Albert Holguin 27-Jun-12 10:09am    
Thanks
Sergey Alexandrovich Kryukov 27-Jun-12 12:41pm    
Good, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900