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. PostThreadMessage(...)???

PostThreadMessage(...)???

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
2 Posts 2 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.
  • Z Offline
    Z Offline
    zhaopzhi
    wrote on last edited by
    #1

    sequence 1: MessageBox(NULL,"a test","a test",MB_OK); BOOL b = PostThreadMessage(threadID,WM_TEST,0,0); sequence 2: BOOL b = PostThreadMessage(threadID,WM_TEST,0,0); MessageBox(NULL,"a test","a test",MB_OK); ---------- The "sequence 1" and the "sequence 2" are identical except for sequence.The return value "b" proved that they sent the message "WM_TEST" successfully.But "sequence 2" didn't made the thread identified by "threadID" receiving the message. Why??? For this, I should how to do??? Thank you in advance! Rap off for you,for me,for our human.

    A 1 Reply Last reply
    0
    • Z zhaopzhi

      sequence 1: MessageBox(NULL,"a test","a test",MB_OK); BOOL b = PostThreadMessage(threadID,WM_TEST,0,0); sequence 2: BOOL b = PostThreadMessage(threadID,WM_TEST,0,0); MessageBox(NULL,"a test","a test",MB_OK); ---------- The "sequence 1" and the "sequence 2" are identical except for sequence.The return value "b" proved that they sent the message "WM_TEST" successfully.But "sequence 2" didn't made the thread identified by "threadID" receiving the message. Why??? For this, I should how to do??? Thank you in advance! Rap off for you,for me,for our human.

      A Offline
      A Offline
      Antti Keskinen
      wrote on last edited by
      #2

      Where is the WM_TEST message supposed to go ? Which thread does threadID designate ? Are you certain that this ID is correct ? The message boxes are, by default, application modal. This means that the message pump handling of the application will pause for during the showing of the message box. In sequence 1, the results of posting the message WM_TEXT are visible only after you close the message box. In sequence 2, they MIGHT BE visible already during the showing of the box. I say, might be, as PostThreadMessage returns before the message itself is handled. In sequence 2, the message is posted to the thread's queue, but if this thread is the same as which is to show the message box, then it might be that the message will not be handled before the message box is closed. So, if threadID points to the same thread as which is to pop up the message box, then the thread's queue will be suspended until the closing of the box. You should never pop up modal message boxed in these type of situations. Use SendMessage to post a message to the thread's main window and wait for the window procedure to handle it. In this case, the application would either first show the message box, then handle the message, or vice versa. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

      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