|
From: He Shiming on 14 Mar 2006 08:09 Hi, I've got a question regarding the timing of PostMessage API. Consider the following code snippet: void Post () { PostMessage(m_hWnd, WM_USER+1, 0, 0); FunctionA(); } LRESULT OnMsg(UINT, WPARAM, LPARAM, BOOL&) { // message handler for WM_USER+1 FunctionB(); } My question is, between FunctionA and FunctionB, which is called first? Is there a guarantee that it's always called first? Thanks in advance, -- He Shiming
From: Igor Tandetnik on 14 Mar 2006 08:20 "He Shiming" <mailbill(NOSPAM)@21cn.com.nospam> wrote in message news:O8Tt6h2RGHA.5728(a)tk2msftngp13.phx.gbl > I've got a question regarding the timing of PostMessage API. Consider > the following code snippet: > > void Post () > { > PostMessage(m_hWnd, WM_USER+1, 0, 0); > FunctionA(); > } > > LRESULT OnMsg(UINT, WPARAM, LPARAM, BOOL&) > { > // message handler for WM_USER+1 > FunctionB(); > } > > My question is, between FunctionA and FunctionB, which is called > first? Is there a guarantee that it's always called first? FunctionA is always called first. PostMessage puts the message into the message queue, where it sits until retrieved by GetMessage and dispatched by DispatchMessage. Your application has to unwind all the way to the message pump before a posted message can be processed. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: He Shiming on 14 Mar 2006 08:25 "Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message news:%23YtQfo2RGHA.1572(a)tk2msftngp13.phx.gbl... > > FunctionA is always called first. PostMessage puts the message into the > message queue, where it sits until retrieved by GetMessage and dispatched > by DispatchMessage. Your application has to unwind all the way to the > message pump before a posted message can be processed. > -- > With best wishes, > Igor Tandetnik > > With sufficient thrust, pigs fly just fine. However, this is not > necessarily a good idea. It is hard to be sure where they are going to > land, and it could be dangerous sitting under them as they fly > overhead. -- RFC 1925 > Thanks! Best regards, He Shiming
From: Norman Bullen on 14 Mar 2006 09:04 Igor Tandetnik wrote: > "He Shiming" <mailbill(NOSPAM)@21cn.com.nospam> wrote in message > news:O8Tt6h2RGHA.5728(a)tk2msftngp13.phx.gbl > >>I've got a question regarding the timing of PostMessage API. Consider >>the following code snippet: >> >>void Post () >>{ >> PostMessage(m_hWnd, WM_USER+1, 0, 0); >> FunctionA(); >>} >> >>LRESULT OnMsg(UINT, WPARAM, LPARAM, BOOL&) >>{ >> // message handler for WM_USER+1 >> FunctionB(); >>} >> >>My question is, between FunctionA and FunctionB, which is called >>first? Is there a guarantee that it's always called first? > > > FunctionA is always called first. PostMessage puts the message into the > message queue, where it sits until retrieved by GetMessage and > dispatched by DispatchMessage. Your application has to unwind all the > way to the message pump before a posted message can be processed. This is not necessarily true in a threaded application. If PostMessage() is in one thread and the message loop for the window in another thread, either function could be called first. On a multiprocessor system they could be called concurrently. Norm -- -- To reply, change domain to an adult feline.
From: He Shiming on 14 Mar 2006 09:34
"Norman Bullen" <norm(a)BlackKittenAssociates.com.INVALID> wrote in message news:D3ARf.3340$x94.2965(a)newsread1.news.pas.earthlink.net... > This is not necessarily true in a threaded application. > > If PostMessage() is in one thread and the message loop for the window in > another thread, either function could be called first. On a multiprocessor > system they could be called concurrently. > > Norm > Well that was quite helpful. I'm actually working on a multithreaded program here. I ran into some trouble which I thought is the problem that the execution sequence of these two functions can be random. He Shiming |