Broadcasting the command
-
I have an MFC app with one CMainFrame, one doc, and multiple views, each view is associated with the same doc but different child frames (CMDIChildFrame).Each view handle certain set of manu commands. If I have updated the doc's data thru one of the views, how do I broadcast the command so that other views can respond the command?
-
I have an MFC app with one CMainFrame, one doc, and multiple views, each view is associated with the same doc but different child frames (CMDIChildFrame).Each view handle certain set of manu commands. If I have updated the doc's data thru one of the views, how do I broadcast the command so that other views can respond the command?
You can invoke the UpdateAllViews method of CDocument. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
-
You can invoke the UpdateAllViews method of CDocument. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
Yes, UpdateAllViews() informs all other views to update their contents. What about if I want other views to respond in a way like following: if ID_COMMAND1 is send by pView1 then I want: pView2->WelcomeYou(); pView3->MakeDinnerForYou(); ... pViewn->GoFishing().. Any idea?
-
Yes, UpdateAllViews() informs all other views to update their contents. What about if I want other views to respond in a way like following: if ID_COMMAND1 is send by pView1 then I want: pView2->WelcomeYou(); pView3->MakeDinnerForYou(); ... pViewn->GoFishing().. Any idea?
Other than using the hint parameters, no, I don't have any ideas. Not totally sure what you want. If X happens in view 1, then you want view 2 to do Y, view 3 to do Z, etc, then the hint parameters should work. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
-
I have an MFC app with one CMainFrame, one doc, and multiple views, each view is associated with the same doc but different child frames (CMDIChildFrame).Each view handle certain set of manu commands. If I have updated the doc's data thru one of the views, how do I broadcast the command so that other views can respond the command?
-
Yes, UpdateAllViews() informs all other views to update their contents. What about if I want other views to respond in a way like following: if ID_COMMAND1 is send by pView1 then I want: pView2->WelcomeYou(); pView3->MakeDinnerForYou(); ... pViewn->GoFishing().. Any idea?
yellowine wrote: if ID_COMMAND1 is send by pView1 then I want: pView2->WelcomeYou(); pView3->MakeDinnerForYou(); ... pViewn->GoFishing().. I think you might maintain a global stack of messages and handle them individually in the individual views iterating through each message in the stack. Push only those msgs into the stack that you wish to have handlers for in the different views. My most recent CP article :- A newbie's elementary guide to spawning processes www.busterboy.org
-
yellowine wrote: if ID_COMMAND1 is send by pView1 then I want: pView2->WelcomeYou(); pView3->MakeDinnerForYou(); ... pViewn->GoFishing().. I think you might maintain a global stack of messages and handle them individually in the individual views iterating through each message in the stack. Push only those msgs into the stack that you wish to have handlers for in the different views. My most recent CP article :- A newbie's elementary guide to spawning processes www.busterboy.org
-
Yes, UpdateAllViews() informs all other views to update their contents. What about if I want other views to respond in a way like following: if ID_COMMAND1 is send by pView1 then I want: pView2->WelcomeYou(); pView3->MakeDinnerForYou(); ... pViewn->GoFishing().. Any idea?
Something like this ? CMyMainWnd::OnCommand1() { CMyDoc* pDoc = GetActiveDocument(); POSITION pos = pDoc->GetFirstViewPosition(); while( pos ) { pView = pDoc->GetNextView( &pos); if( pView->IsKindOf(RUNTIME_CLASS(CMyView1))) { ((CMyView1*)pView)->WelcomeYou(); } ....etc } }
-
Something like this ? CMyMainWnd::OnCommand1() { CMyDoc* pDoc = GetActiveDocument(); POSITION pos = pDoc->GetFirstViewPosition(); while( pos ) { pView = pDoc->GetNextView( &pos); if( pView->IsKindOf(RUNTIME_CLASS(CMyView1))) { ((CMyView1*)pView)->WelcomeYou(); } ....etc } }
Thanks for your idea. I do think this approach works except a maintainence problem. Any time I add a view or I have a new command which will cause a train reaction for other view, I have to add a new handler in the CMyMainFrame or add a new IsKindOf(..) in the while loop, right?
-
Thanks for your idea. I do think this approach works except a maintainence problem. Any time I add a view or I have a new command which will cause a train reaction for other view, I have to add a new handler in the CMyMainFrame or add a new IsKindOf(..) in the while loop, right?