Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Broadcasting the command

Broadcasting the command

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yellowine
    wrote on last edited by
    #1

    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?

    T L 2 Replies Last reply
    0
    • Y yellowine

      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?

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      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?

      Y 1 Reply Last reply
      0
      • T Tim Smith

        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?

        Y Offline
        Y Offline
        yellowine
        wrote on last edited by
        #3

        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?

        T N P 3 Replies Last reply
        0
        • Y yellowine

          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?

          T Offline
          T Offline
          Tim Smith
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • Y yellowine

            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?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Think about overriding OnCmdMsg( )and route the messages yourself.

            Y 1 Reply Last reply
            0
            • Y yellowine

              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?

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #6

              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

              Y 1 Reply Last reply
              0
              • N Nish Nishant

                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

                Y Offline
                Y Offline
                yellowine
                wrote on last edited by
                #7

                Good idea. Thanks.

                1 Reply Last reply
                0
                • L Lost User

                  Think about overriding OnCmdMsg( )and route the messages yourself.

                  Y Offline
                  Y Offline
                  yellowine
                  wrote on last edited by
                  #8

                  I will take this approach and give it a try. Thanks.

                  1 Reply Last reply
                  0
                  • Y yellowine

                    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?

                    P Offline
                    P Offline
                    pba_
                    wrote on last edited by
                    #9

                    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 } }

                    Y 1 Reply Last reply
                    0
                    • P pba_

                      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 } }

                      Y Offline
                      Y Offline
                      yellowine
                      wrote on last edited by
                      #10

                      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?

                      P 1 Reply Last reply
                      0
                      • Y yellowine

                        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?

                        P Offline
                        P Offline
                        pba_
                        wrote on last edited by
                        #11

                        Or you can send the message to each view ... // while(....) { pView->SendMessage( ); } and each view will process the message in his own way.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups