Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. PostMessage

PostMessage

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sschilachi
    wrote on last edited by
    #1

    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

    P E 2 Replies Last reply
    0
    • S sschilachi

      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

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      both 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.

      1 Reply Last reply
      0
      • S sschilachi

        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

        E Offline
        E Offline
        Empty1981
        wrote on last edited by
        #3

        ::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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups