Windows Message Confusion! Gurus come and help!
-
I have a windows message problem that has haunted me for a long time. Suppose one application has two thread. Thread A "sends" and "posts" message to a window handle in thread B. Thread A { LOOP{ ... SendMessage(m_hwnd, msg1); ... PostMessage(m_hwnd, msg2); ... } } in winproc of Thread B: Winproc { case (msg1): do something ... case (msg2): do something ... } my question is: if Thread B is processing msg2, and Thread A are going to send msg1 , Thread A will wait until Thread B finishes processing msg2??
-
I have a windows message problem that has haunted me for a long time. Suppose one application has two thread. Thread A "sends" and "posts" message to a window handle in thread B. Thread A { LOOP{ ... SendMessage(m_hwnd, msg1); ... PostMessage(m_hwnd, msg2); ... } } in winproc of Thread B: Winproc { case (msg1): do something ... case (msg2): do something ... } my question is: if Thread B is processing msg2, and Thread A are going to send msg1 , Thread A will wait until Thread B finishes processing msg2??
The very definition of
SendMessage()
says that control does not return until the window procedure (the one in thread B) has processed the message. If this is a problem, useSendMessageTimeout()
instead.
"Take only what you need and leave the land as you found it." - Native American Proverb
-
The very definition of
SendMessage()
says that control does not return until the window procedure (the one in thread B) has processed the message. If this is a problem, useSendMessageTimeout()
instead.
"Take only what you need and leave the land as you found it." - Native American Proverb
Hi David,does that mean: Thread B will always process msg1 then msg2 ,again and again? it could not process two continous msg2?? However, I found in my project, this situation happens, but not often! -- modified at 11:54 Wednesday 7th December, 2005
-
I have a windows message problem that has haunted me for a long time. Suppose one application has two thread. Thread A "sends" and "posts" message to a window handle in thread B. Thread A { LOOP{ ... SendMessage(m_hwnd, msg1); ... PostMessage(m_hwnd, msg2); ... } } in winproc of Thread B: Winproc { case (msg1): do something ... case (msg2): do something ... } my question is: if Thread B is processing msg2, and Thread A are going to send msg1 , Thread A will wait until Thread B finishes processing msg2??
No. Thread B will process msg1 and the SendMessage call in Thread A will only return when Thread B has finished processing. Then Thread A will Post msg2 but the PostMessage call will return immediately without waiting for Thread B to process it. Then it may be possible for Thread A to return to the top of the loop and send another msg1 while Thread B is still processing msg2. That is precisely the way SendMessage and PostMessage are designed: SendMessage waits for processing, PostMessage doesn't wait.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
-
I have a windows message problem that has haunted me for a long time. Suppose one application has two thread. Thread A "sends" and "posts" message to a window handle in thread B. Thread A { LOOP{ ... SendMessage(m_hwnd, msg1); ... PostMessage(m_hwnd, msg2); ... } } in winproc of Thread B: Winproc { case (msg1): do something ... case (msg2): do something ... } my question is: if Thread B is processing msg2, and Thread A are going to send msg1 , Thread A will wait until Thread B finishes processing msg2??
jinzhecheng wrote:
my question is: if Thread B is processing msg2, and Thread A are going to send msg1 , Thread A will wait until Thread B finishes processing msg2??
Offcourse... Thread B should finish previous Message Processing before taking new task...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV