How do I post a message to a CDocument?
-
Is it possible to post a message to a CDocument derived class? I am curious because I noticed that it has a BEGIN_MESSAGE_MAP()/END_MESSAGE_MAP(). Plus it would be really handy if I could have a thread post a message to the document so that it is updated. I know I can do this if I post a message to a CView, but I would like to do it to the document then have the document update the views using something like UpdateAllViews(). Cheers, Clint
-
Is it possible to post a message to a CDocument derived class? I am curious because I noticed that it has a BEGIN_MESSAGE_MAP()/END_MESSAGE_MAP(). Plus it would be really handy if I could have a thread post a message to the document so that it is updated. I know I can do this if I post a message to a CView, but I would like to do it to the document then have the document update the views using something like UpdateAllViews(). Cheers, Clint
A document is not a window, so you cannot post arbitrary messages to it. You can send
WM_COMMAND
messages to it, but only because MFC handles the message routing itself.CDocument
is derived fromCCmdTarget
, which means "can be the target of aWM_COMMAND
message" --Mike-- THERE IS NO THERE IS NO BUT THERE IS MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT BUY MY SOFTWARE!! (please?) RightClick-Encrypt | 1ClickPicGrabber My IntarWeb Homepgae!!!11 -
Is it possible to post a message to a CDocument derived class? I am curious because I noticed that it has a BEGIN_MESSAGE_MAP()/END_MESSAGE_MAP(). Plus it would be really handy if I could have a thread post a message to the document so that it is updated. I know I can do this if I post a message to a CView, but I would like to do it to the document then have the document update the views using something like UpdateAllViews(). Cheers, Clint
Why don't you just post a message to the MainFrame and then use GetActiveDocument()->UpdateAllViews(...)? Also use (CDocumentClassName *)GetActiveDocument()->SpecialProcessingFunctions(..) in the MainFrame to do any document manipulations which can also be message or timer driven. Steve
-
Why don't you just post a message to the MainFrame and then use GetActiveDocument()->UpdateAllViews(...)? Also use (CDocumentClassName *)GetActiveDocument()->SpecialProcessingFunctions(..) in the MainFrame to do any document manipulations which can also be message or timer driven. Steve
This way it goes more Frame/Doc/View architecture than the pure Doc/View. ;) I would personally avoid coding logic in the frame window unless it's absolutely needed (which is not the case). The message map in CDocument class can be nicely utilized to handle menu/toolbar/accelerator messages that are related to the document. Try to create message handlers in the classes that own the variables you use in these handlers, so there is nothing like
((CDocumentClassName *)CFrameWnd::GetActiveDocument())->SpecialProcessingFunctions(..)
, but ratherCDocumentClassName::OnSpecial()
. :rolleyes: Regards, BB -
A document is not a window, so you cannot post arbitrary messages to it. You can send
WM_COMMAND
messages to it, but only because MFC handles the message routing itself.CDocument
is derived fromCCmdTarget
, which means "can be the target of aWM_COMMAND
message" --Mike-- THERE IS NO THERE IS NO BUT THERE IS MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT BUY MY SOFTWARE!! (please?) RightClick-Encrypt | 1ClickPicGrabber My IntarWeb Homepgae!!!11Thank you for the clarification. Perhaps you could answer another question. I have a thread that is owned by the CDocument derived class. The threads sole purpose is to wait on some incomming data then update a structure in the document. The problem I was running into is that when I called
UpdateAllViews
I wouldASSERT()
because of some issues with multithreaded programs and c++ objects. I thought then that I could just update the data, then post a message to the document which in turn callsUpdateAllViews
. That way there wouldn't be a problem. Any suggestions? Cheers, Clint