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. Windows Message Confusion! Gurus come and help!

Windows Message Confusion! Gurus come and help!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 4 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.
  • J Offline
    J Offline
    jinzhecheng
    wrote on last edited by
    #1

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

    D P T 3 Replies Last reply
    0
    • J jinzhecheng

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

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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, use SendMessageTimeout() instead.


      "Take only what you need and leave the land as you found it." - Native American Proverb

      J 1 Reply Last reply
      0
      • D David Crow

        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, use SendMessageTimeout() instead.


        "Take only what you need and leave the land as you found it." - Native American Proverb

        J Offline
        J Offline
        jinzhecheng
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • J jinzhecheng

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

          P Offline
          P Offline
          Phil J Pearson
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • J jinzhecheng

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

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            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

            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