Sometime you need to send/post message to CDoumnet, but CDocument is not a window, and it can’t receive message. How do that?
There are 3 solutions:
Solution 1: Send the message to the main window.
Send/Post the message to the main frame or the view, and then call some functions of the document.
But if in a MDI app, it does not work, because the routing becomes too complex. Typically, you can send message to a view, but that has risks if there are multiple views on the same document and the one you post message to has been closed.
Solution 2: Use WM_COMMAND message.
A document can’t recerive a message, but it can recerives the commands through MFC’s command mechanism. Then you can use ::PostMessage to post WM_COMMAND message, and repose it in the document.
Solution 3:
Create an invisible top-level window in the CDocument, that represents its message sink. You send/post message to it. Thus will eliminate the complex route policy between the main frame and the views and you don’t worry about the view closing.
Tags: Document, How-to, message, PostMessage, SendMessage, WindowPermalink: Code Library - How to send/post message to CDocument?
Subcribe the update with Google Reader.
2 Responses
Alexwebmaster
March 3rd, 2009 at 4:24 pm
1Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
Victor
May 12th, 2009 at 5:57 am
2Can you give an example as to where to create the hidden window and proving the syntax on the Create function because I cannot do this ?
RSS feed for comments on this post · TrackBack URI
Leave a reply
Category
Recent Posts
Hot Posts
Creative Commons
Code Library