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. MFC messages

MFC messages

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
3 Posts 3 Posters 1 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.
  • L Offline
    L Offline
    Luke Murray
    wrote on last edited by
    #1

    Hey all, in my view class i have it create a Object of mine that uses a thread to complete it's task, when the thread finishes it users AfxGetMainWnd()->PostMessage(MY_MESSAGE, 0, 0); to post a message. I am trying to catch it in the view class with ON_MESSAGE(MY_MESSAGE, MyFunction) but no luck. tho if I put that in the MainFrame class it catches it. Any ideas on how to get the view class to notice this message? thanks in advanced. Luke.

    P J 2 Replies Last reply
    0
    • L Luke Murray

      Hey all, in my view class i have it create a Object of mine that uses a thread to complete it's task, when the thread finishes it users AfxGetMainWnd()->PostMessage(MY_MESSAGE, 0, 0); to post a message. I am trying to catch it in the view class with ON_MESSAGE(MY_MESSAGE, MyFunction) but no luck. tho if I put that in the MainFrame class it catches it. Any ideas on how to get the view class to notice this message? thanks in advanced. Luke.

      P Offline
      P Offline
      Prem Kumar
      wrote on last edited by
      #2

      OK, It's something like this, the Message Pumps are associated with a thread and not a window. Inside this thread the messages are dispatched to different windows based on the windows handles. So your code is posting back to the same thread which does not have a message pump (while(GetMessage(..) {...}) so what ever messages you post will never be executed! Now you have two options 1. Post the message to the main thread and have it executed there by using PostThreadMessage. 2. Provide a message Pump (this will mean you will need to re-tailor your existing thread function to use the message pump and not the simple while) Hope this helps..

      1 Reply Last reply
      0
      • L Luke Murray

        Hey all, in my view class i have it create a Object of mine that uses a thread to complete it's task, when the thread finishes it users AfxGetMainWnd()->PostMessage(MY_MESSAGE, 0, 0); to post a message. I am trying to catch it in the view class with ON_MESSAGE(MY_MESSAGE, MyFunction) but no luck. tho if I put that in the MainFrame class it catches it. Any ideas on how to get the view class to notice this message? thanks in advanced. Luke.

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        Post a user-defined command instead with AfxGetMainWnd()->PostMessage(WM_COMMAND,MAKEWORD(0,ID_YOURCOMMAND,0); and add an ON_COMMAND handler to your view: the MFC framework will properly route the command to the view handler. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        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