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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC How to update CMDIChildWnd from CDocument

MFC How to update CMDIChildWnd from CDocument

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorialannouncement
18 Posts 4 Posters 22 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.
  • A Adam Roderick J

    You can call UpdateAllViews with a hind to update a particular view Please refer for more details [^]

    Величие не Бога может быть недооценена.

    B Offline
    B Offline
    baumchen
    wrote on last edited by
    #3

    thanks for the reply. but updateview doesn't solve my problem, as scrollbar doesn't belong to a specific view (it belongs to CMDIChildWnd), and I need to update it too. any idea? thanks!

    A 1 Reply Last reply
    0
    • B baumchen

      thanks for the reply. but updateview doesn't solve my problem, as scrollbar doesn't belong to a specific view (it belongs to CMDIChildWnd), and I need to update it too. any idea? thanks!

      A Offline
      A Offline
      Adam Roderick J
      wrote on last edited by
      #4

      I think you dont need to update the CMDIChildWnd.

      Величие не Бога может быть недооценена.

      modified on Tuesday, January 19, 2010 12:19 AM

      B 1 Reply Last reply
      0
      • A Adam Roderick J

        I think you dont need to update the CMDIChildWnd.

        Величие не Бога может быть недооценена.

        modified on Tuesday, January 19, 2010 12:19 AM

        B Offline
        B Offline
        baumchen
        wrote on last edited by
        #5

        it is not, it is a CFrameWnd, container of CDocument and CView.

        A 1 Reply Last reply
        0
        • B baumchen

          it is not, it is a CFrameWnd, container of CDocument and CView.

          A Offline
          A Offline
          Adam Roderick J
          wrote on last edited by
          #6

          I think what you want to achieve is update two scroll views from the document? i.e on update the two views simultanously?

          Величие не Бога может быть недооценена.

          B 1 Reply Last reply
          0
          • A Adam Roderick J

            I think what you want to achieve is update two scroll views from the document? i.e on update the two views simultanously?

            Величие не Бога может быть недооценена.

            B Offline
            B Offline
            baumchen
            wrote on last edited by
            #7

            exactly. but I don't want to use two scrollbars, is it achievable?

            A 1 Reply Last reply
            0
            • B baumchen

              exactly. but I don't want to use two scrollbars, is it achievable?

              A Offline
              A Offline
              Adam Roderick J
              wrote on last edited by
              #8

              I hope you want two Views, both derived from CScrollView? and using a single class. If so then UpdateAllView is what you need.

              Величие не Бога может быть недооценена.

              B 1 Reply Last reply
              0
              • B baumchen

                Hi, folks I am thinking of writing a program which opens two files in one window. and these two files needs to be scrolled simulateneously. (I have to put the scrollbar here as I have multiple views). I plan to use such a structure CMDIChildWnd, which has a scrollbar, and CSplitterWnd, its role is to change answer scroll related message such as OnSize, OnScroll. CView, handles OnDraw, displays file. CDocument, which has files info. (I need to take advantage of OnOpenDocument) the question is, when I load a file (which is handled by CDocument) either by OnOpenDocument() or some user defined open file function, how could I update CMDIChildWnd? thanks in advance! baum

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #9

                I think you can get 2 CScrollViews and manage who is scrolling (the View is active) when you do the click in one of the scrolls, then from the document you get the new scroll position, give it to the other window using SetScrollPosition with pDoc->ActualPos_2 (assuming you made the click on View1) for the other one and call UpdateAllViews. Or just setting the scroll for both views where you need and call UpdateAllViews when opening a document. Is that more or less what you wanted?

                Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

                B 1 Reply Last reply
                0
                • N Nelek

                  I think you can get 2 CScrollViews and manage who is scrolling (the View is active) when you do the click in one of the scrolls, then from the document you get the new scroll position, give it to the other window using SetScrollPosition with pDoc->ActualPos_2 (assuming you made the click on View1) for the other one and call UpdateAllViews. Or just setting the scroll for both views where you need and call UpdateAllViews when opening a document. Is that more or less what you wanted?

                  Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

                  B Offline
                  B Offline
                  baumchen
                  wrote on last edited by
                  #10

                  Nelek wrote:

                  Or just setting the scroll for both views where you need

                  could you give a little bit more info? are both views scrollviews or there is a scrollbar on top of them? if both are scrollviews, how can I set scroll for both views? which class should handle scroll message? thanks!

                  N 1 Reply Last reply
                  0
                  • A Adam Roderick J

                    I hope you want two Views, both derived from CScrollView? and using a single class. If so then UpdateAllView is what you need.

                    Величие не Бога может быть недооценена.

                    B Offline
                    B Offline
                    baumchen
                    wrote on last edited by
                    #11

                    i planed to use two views, and attached a scrollbar to CMDIChildWnd (i can't attach scrollbar to CDocument, as it is not a CWnd). UpdateAllView only affect views, but not their container CMDIChildWnd. If using scrollviews, I need to synchronize two scrollbars.....

                    1 Reply Last reply
                    0
                    • B baumchen

                      Hi, folks I am thinking of writing a program which opens two files in one window. and these two files needs to be scrolled simulateneously. (I have to put the scrollbar here as I have multiple views). I plan to use such a structure CMDIChildWnd, which has a scrollbar, and CSplitterWnd, its role is to change answer scroll related message such as OnSize, OnScroll. CView, handles OnDraw, displays file. CDocument, which has files info. (I need to take advantage of OnOpenDocument) the question is, when I load a file (which is handled by CDocument) either by OnOpenDocument() or some user defined open file function, how could I update CMDIChildWnd? thanks in advance! baum

                      C Offline
                      C Offline
                      Cliff Hatch
                      wrote on last edited by
                      #12

                      I'm not sure if this exactly fits your requirement, but it is possible to place two views derived from CScrollView into different panes of a splitter window and scroll them together. You need to specify WS_VSCROLL when you create the splitter, otherwise you get a scrollbar for each pane instead of one that works them both. I used WS_HSCROLL and WS_VSCROLL in a recent application to scroll around a matrix and get the row and column headings to scroll along with the body of the matrix. Like this (CMatrixSplitterFrame derived from CMDIChildWnd):

                      BOOL CMatrixSplitterFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
                      {
                      //Create a splitter with 2 rows and 2 columns
                      if (!m_SplitterWnd.CreateStatic(this, 2, 2, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL)) //Specify WS_HSCROLL and WS_VSCROLL to get one set of horizontal and vertical scrollbars for the splitter window instead of both in each pane.
                      {
                      TRACE0("Failed to CreateStaticSplitter\n");
                      return FALSE;
                      }

                      //Add column headings pane
                      if (!m\_SplitterWnd.CreateView(0, 1,	RUNTIME\_CLASS(CKernelMatrixColHeadView), CSize(2000, CELL\_YSIZE + CELL\_INTER\_GAP + CELL\_INTER\_GAP), pContext))
                      {
                      	TRACE0("Failed to create second pane\\n");
                      	return FALSE;
                      }
                          //etc..
                      

                      Best Regards Cliff Hatch

                      B 1 Reply Last reply
                      0
                      • C Cliff Hatch

                        I'm not sure if this exactly fits your requirement, but it is possible to place two views derived from CScrollView into different panes of a splitter window and scroll them together. You need to specify WS_VSCROLL when you create the splitter, otherwise you get a scrollbar for each pane instead of one that works them both. I used WS_HSCROLL and WS_VSCROLL in a recent application to scroll around a matrix and get the row and column headings to scroll along with the body of the matrix. Like this (CMatrixSplitterFrame derived from CMDIChildWnd):

                        BOOL CMatrixSplitterFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
                        {
                        //Create a splitter with 2 rows and 2 columns
                        if (!m_SplitterWnd.CreateStatic(this, 2, 2, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL)) //Specify WS_HSCROLL and WS_VSCROLL to get one set of horizontal and vertical scrollbars for the splitter window instead of both in each pane.
                        {
                        TRACE0("Failed to CreateStaticSplitter\n");
                        return FALSE;
                        }

                        //Add column headings pane
                        if (!m\_SplitterWnd.CreateView(0, 1,	RUNTIME\_CLASS(CKernelMatrixColHeadView), CSize(2000, CELL\_YSIZE + CELL\_INTER\_GAP + CELL\_INTER\_GAP), pContext))
                        {
                        	TRACE0("Failed to create second pane\\n");
                        	return FALSE;
                        }
                            //etc..
                        

                        Best Regards Cliff Hatch

                        B Offline
                        B Offline
                        baumchen
                        wrote on last edited by
                        #13

                        Cliff, thanks for the clue, it is very useful.

                        BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT, CCreateContext* pContext)
                        {
                        // create a splitter with 1 row, 2 columns
                        if (!m_SplitterController.CreateStatic(this, 1, 2, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL))
                        {
                        return FALSE;
                        }

                        CRect		lRect;
                        
                        GetClientRect(lRect);
                        
                        // add the first splitter pane - the default view in column 0
                        if (!m\_SplitterController.CreateView(0, 0, pContext->m\_pNewViewClass, 
                        	CSize(lRect.Width() >> 1, lRect.Height()), pContext))
                        {
                        	return FALSE;
                        }
                        
                        // add the second splitter pane - an input view in column 1
                        if (!m\_SplitterController.CreateView(0, 1, pContext->m\_pNewViewClass, 
                        	CSize((lRect.Width() + 1) >> 1, lRect.Height()), pContext))
                        {
                        	return FALSE;
                        }
                        
                        // activate the input view
                        SetActiveView((CView\*)m\_SplitterController.GetPane(0, 1));
                        
                        m\_IsInitialized = TRUE;
                        
                        return TRUE;
                        

                        however, it only partly works at here --- there is only one vertical scroll bar, but there are two horizontal scroll bars, did I miss anything? and, how do you answer scroll message? I added it to CChildFrame, which is a subclass of CMDIChildWnd, but it was never called.

                        afx\_msg void	OnHScroll(UINT nSBCode, UINT nPos, CScrollBar\* pScrollBar);
                        afx\_msg void	OnVScroll(UINT nSBCode, UINT nPos, CScrollBar\* pScrollBar);
                        

                        ...

                        BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
                        ON_WM_HSCROLL()
                        ON_WM_VSCROLL()
                        ON_WM_MOUSEWHEEL()
                        ON_WM_SIZE()
                        END_MESSAGE_MAP()

                        ...

                        void CChildFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
                        {
                        CMDIChildWnd::OnHScroll(nSBCode, nPos, pScrollBar);
                        }

                        any idea? many thanks!

                        C 1 Reply Last reply
                        0
                        • B baumchen

                          Nelek wrote:

                          Or just setting the scroll for both views where you need

                          could you give a little bit more info? are both views scrollviews or there is a scrollbar on top of them? if both are scrollviews, how can I set scroll for both views? which class should handle scroll message? thanks!

                          N Offline
                          N Offline
                          Nelek
                          wrote on last edited by
                          #14

                          It would be using GetScrollPosition in the view that is getting scrolled with the OnScroll and sending it to the other view where you use it with SetScrollPosition before updating all views. Yes, both views should be derived from CScrollView and each one would have its own scrollbar, but you synchronize one when moving the other Here[^] is spoken about SetScrollPos and Here[^] about ScrollToPosition If you manage the actual position of each View in the document, for instance m_pScrollPos_1 and m_pSCrollPos_2, you can call them in your OnDraw and move the actual position of the scroll for this view to the saved point. When you click on a scroll bar just save the new position in the document and call pDoc->UpdateAllViews. It may have a bit delayment between the one and the other whilst synchronising. But it is a possibility

                          Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

                          B 1 Reply Last reply
                          0
                          • B baumchen

                            Cliff, thanks for the clue, it is very useful.

                            BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT, CCreateContext* pContext)
                            {
                            // create a splitter with 1 row, 2 columns
                            if (!m_SplitterController.CreateStatic(this, 1, 2, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL))
                            {
                            return FALSE;
                            }

                            CRect		lRect;
                            
                            GetClientRect(lRect);
                            
                            // add the first splitter pane - the default view in column 0
                            if (!m\_SplitterController.CreateView(0, 0, pContext->m\_pNewViewClass, 
                            	CSize(lRect.Width() >> 1, lRect.Height()), pContext))
                            {
                            	return FALSE;
                            }
                            
                            // add the second splitter pane - an input view in column 1
                            if (!m\_SplitterController.CreateView(0, 1, pContext->m\_pNewViewClass, 
                            	CSize((lRect.Width() + 1) >> 1, lRect.Height()), pContext))
                            {
                            	return FALSE;
                            }
                            
                            // activate the input view
                            SetActiveView((CView\*)m\_SplitterController.GetPane(0, 1));
                            
                            m\_IsInitialized = TRUE;
                            
                            return TRUE;
                            

                            however, it only partly works at here --- there is only one vertical scroll bar, but there are two horizontal scroll bars, did I miss anything? and, how do you answer scroll message? I added it to CChildFrame, which is a subclass of CMDIChildWnd, but it was never called.

                            afx\_msg void	OnHScroll(UINT nSBCode, UINT nPos, CScrollBar\* pScrollBar);
                            afx\_msg void	OnVScroll(UINT nSBCode, UINT nPos, CScrollBar\* pScrollBar);
                            

                            ...

                            BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
                            ON_WM_HSCROLL()
                            ON_WM_VSCROLL()
                            ON_WM_MOUSEWHEEL()
                            ON_WM_SIZE()
                            END_MESSAGE_MAP()

                            ...

                            void CChildFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
                            {
                            CMDIChildWnd::OnHScroll(nSBCode, nPos, pScrollBar);
                            }

                            any idea? many thanks!

                            C Offline
                            C Offline
                            Cliff Hatch
                            wrote on last edited by
                            #15

                            baumchen It looks as though the scrollbars are associated with the panes in a manner that happened to be right for my application, but is perhaps not right for yours. When you specify WS_HSCROLL and WS_VSCROLL you get a horizontal scrollbar on all the panes along the bottom of the window, and a vertical scrollbar on all those on the right hand side. So in my 2x2 display I have 4 scrollbars in total. (Without WS_HSCROLL and WS_VSCROLL there would be 8, 2 for each pane). Sorry, the description in my earlier post was a little misleading. I had forgotten the existence of 2 of my scrollbars because the top row is sized such that it never needs vertical scrolling, and the left column never needs horizontal scrolling - so their bars are always grayed out. It appears that the horizontal scrollbars are shared by all the panes stacked above them, and the vertical ones by all the panes on the row to their left. I haven't been able to test this completely because my top-left pane is a dummy - but this is certainly how the other 3 behave. This would be consistent with your result. In a 1 row x 2 column display, you only get one shared scrollbar - the vertical one. I haven't managed to find any documentation to confirm this, but Technical Note 29 (.Net 2002) has a very short section on shared scroll bars which hints at this arrangment. I didn't write any special handlers. The base classes, CSplitterWnd and CScrollView, managed all the scrolling messages for me. Best Wishes Cliff

                            B 1 Reply Last reply
                            0
                            • N Nelek

                              It would be using GetScrollPosition in the view that is getting scrolled with the OnScroll and sending it to the other view where you use it with SetScrollPosition before updating all views. Yes, both views should be derived from CScrollView and each one would have its own scrollbar, but you synchronize one when moving the other Here[^] is spoken about SetScrollPos and Here[^] about ScrollToPosition If you manage the actual position of each View in the document, for instance m_pScrollPos_1 and m_pSCrollPos_2, you can call them in your OnDraw and move the actual position of the scroll for this view to the saved point. When you click on a scroll bar just save the new position in the document and call pDoc->UpdateAllViews. It may have a bit delayment between the one and the other whilst synchronising. But it is a possibility

                              Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

                              B Offline
                              B Offline
                              baumchen
                              wrote on last edited by
                              #16

                              nelek thanks for the detailed info.

                              N 1 Reply Last reply
                              0
                              • C Cliff Hatch

                                baumchen It looks as though the scrollbars are associated with the panes in a manner that happened to be right for my application, but is perhaps not right for yours. When you specify WS_HSCROLL and WS_VSCROLL you get a horizontal scrollbar on all the panes along the bottom of the window, and a vertical scrollbar on all those on the right hand side. So in my 2x2 display I have 4 scrollbars in total. (Without WS_HSCROLL and WS_VSCROLL there would be 8, 2 for each pane). Sorry, the description in my earlier post was a little misleading. I had forgotten the existence of 2 of my scrollbars because the top row is sized such that it never needs vertical scrolling, and the left column never needs horizontal scrolling - so their bars are always grayed out. It appears that the horizontal scrollbars are shared by all the panes stacked above them, and the vertical ones by all the panes on the row to their left. I haven't been able to test this completely because my top-left pane is a dummy - but this is certainly how the other 3 behave. This would be consistent with your result. In a 1 row x 2 column display, you only get one shared scrollbar - the vertical one. I haven't managed to find any documentation to confirm this, but Technical Note 29 (.Net 2002) has a very short section on shared scroll bars which hints at this arrangment. I didn't write any special handlers. The base classes, CSplitterWnd and CScrollView, managed all the scrolling messages for me. Best Wishes Cliff

                                B Offline
                                B Offline
                                baumchen
                                wrote on last edited by
                                #17

                                Cliff thanks! looks it is easier to live with two sets of scrollbars.

                                1 Reply Last reply
                                0
                                • B baumchen

                                  nelek thanks for the detailed info.

                                  N Offline
                                  N Offline
                                  Nelek
                                  wrote on last edited by
                                  #18

                                  You are welcome. I hope it works as you whish. :)

                                  Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

                                  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