MFC messages
-
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.
-
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.
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..
-
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.
Post a user-defined command instead with
AfxGetMainWnd()->PostMessage(WM_COMMAND,MAKEWORD(0,ID_YOURCOMMAND,0);
and add anON_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