User defined messages to the Document

  • Thread starter Thread starter raphtee
  • Start date Start date
R

raphtee

This is probably a simple/stupid question, but...

I have an MDI application which has a socket receiving data. When the
data is received it is displayed in some way. Sometimes the data that
is received is new and sometimes it is just an update. If something
in the document hasn't been updated in awhile it needs to be removed
and the view updated to reflect this. I decided to have a timer
thread. A worker thread that sits there and every second checks all
the data and any thing that has been there ahile it discards. Easy.
But Now after it has discarded it it needs to update the view
(Actually call UpdateAllviews() ). Of course a worker thread just
can't call UpdateAllViews(). So I need the thread to post a message.
The books I have require that the way this is done is to call
::PostMessage(hWnd, WM_USERMESSAGE, wParam, lParam) and the examples
all have the message handler in the CView class to which the hWnd
refers to an instance of. So now I am just doing that and having the
handler in the View class call the UpdateAllViews() which works,
but.... Isn't there a better way?? Can't I post a message directly
to the Documentclass and have a handler there take care of it??

raphtee
 
but.... Isn't there a better way?? Can't I post a message directly
to the Documentclass and have a handler there take care of it??

Only WM_COMMAND messages get routed to the document. See the topic
titled "Message Categories" in MSDN.

Dave
 
David Lowndes said:
Only WM_COMMAND messages get routed to the document. See the topic
titled "Message Categories" in MSDN.

Dave

Thanks for the help. I was using a WM_COMMAND message. But I was
using ::PostMessage() in the Timer Thread (which is just a worker
thread) to post the message and this function requires a window handle
to know where the message should go. I was using the window handle of
one of the views to which the document was attached. Can I use the
window handle of the main frame instead??

raphtee
 
Thanks for the help. I was using a WM_COMMAND message. But I was
using ::PostMessage() in the Timer Thread (which is just a worker
thread) to post the message and this function requires a window handle
to know where the message should go. I was using the window handle of
one of the views to which the document was attached. Can I use the
window handle of the main frame instead??

Give it a try!

Dave
 
Back
Top