PostMessage
-
I have a function that responds to a message by incrementing a counter variable by 1:
OnAction(WPARAM wParam, LPARAM lParam) { m_nCounter += 1; }
The message that it responds to is posted twice using PostMessage, once immediately after the other (like so):::PostMessage(GetSafeHwnd(),WM_ACTION,0,0); ::PostMessage(GetSafeHwnd(),WM_ACTION,0,0);
The strange thing is that if i modify the function to display a MessageBox with the value of the counter (like so):OnAction(WPARAM wParam, LPARAM lParam) { CString string; m_nCounter += 1; string.Format("%d",m_nCounter); MessageBox(string); }
I get two message boxes, as I should; however the values in the message boxes are 2 then 1, not 1 then 2. Howcome I am receiving 2 then 1, rather than 1 then 2 from the message boxes as you would expect? Any help would be greatly appreciated. Thanks -
I have a function that responds to a message by incrementing a counter variable by 1:
OnAction(WPARAM wParam, LPARAM lParam) { m_nCounter += 1; }
The message that it responds to is posted twice using PostMessage, once immediately after the other (like so):::PostMessage(GetSafeHwnd(),WM_ACTION,0,0); ::PostMessage(GetSafeHwnd(),WM_ACTION,0,0);
The strange thing is that if i modify the function to display a MessageBox with the value of the counter (like so):OnAction(WPARAM wParam, LPARAM lParam) { CString string; m_nCounter += 1; string.Format("%d",m_nCounter); MessageBox(string); }
I get two message boxes, as I should; however the values in the message boxes are 2 then 1, not 1 then 2. Howcome I am receiving 2 then 1, rather than 1 then 2 from the message boxes as you would expect? Any help would be greatly appreciated. Thanksboth the message box comes on together? as far as i know, message boxes in certain events could be very tough way of debuging the app coz the message boxes starts pumping the messages, so other messages too gets executed. try TRACE instead.
MSN Messenger. prakashnadar@msn.com "If history isn't good, just burn it." - Sidhuism.
-
I have a function that responds to a message by incrementing a counter variable by 1:
OnAction(WPARAM wParam, LPARAM lParam) { m_nCounter += 1; }
The message that it responds to is posted twice using PostMessage, once immediately after the other (like so):::PostMessage(GetSafeHwnd(),WM_ACTION,0,0); ::PostMessage(GetSafeHwnd(),WM_ACTION,0,0);
The strange thing is that if i modify the function to display a MessageBox with the value of the counter (like so):OnAction(WPARAM wParam, LPARAM lParam) { CString string; m_nCounter += 1; string.Format("%d",m_nCounter); MessageBox(string); }
I get two message boxes, as I should; however the values in the message boxes are 2 then 1, not 1 then 2. Howcome I am receiving 2 then 1, rather than 1 then 2 from the message boxes as you would expect? Any help would be greatly appreciated. Thanks::SendMessage(GetSafeHwnd(),WM_ACTION,0,0); ::SendMessage(GetSafeHwnd(),WM_ACTION,0,0); if you want to get the result as you say,you should write like these. when we use postmessage to send the message,the application only send the message to CWnd,then return,the application does not wait for the Command to be carried out. when we use sendmessage to send the message,the appliation return when the command be carried out.If we does not wait for the command to be carried out.The message will be save in the message queue, so the message is FILO,not FIFO zhengyb@nanjing-fnst.com