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. UpdateAllViews

UpdateAllViews

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 3 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.
  • S Offline
    S Offline
    sawerr
    wrote on last edited by
    #1

    Hi When clicks on View, my program draws ellipse and I tried to make all changes in one view reflects to all views. 1-)OnLbuttonDown adds a point to CArray m_PointList 2-)UpdateAllViews calls OnUpdate 3-) OnUpdate Invaliates so OnDraw called.

    void CDocumentView::OnLButtonDown(UINT nFlags, CPoint point)
    {
    GetDocument()->m_PointList.Add(point);
    GetDocument()->UpdateAllViews(NULL);

    CView::OnLButtonDown(nFlags, point);
    

    };
    //
    void CDocumentView::OnDraw(CDC* pDC)
    {
    CDocumentDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
    return;
    for(int i = 0; i < GetDocument()->m_PointList.GetCount(); i++)
    {
    pDC->Ellipse(GetDocument()->m_PointList[i].x - GetDocument()->m_PointSize,
    GetDocument()->m_PointList[i].y - GetDocument()->m_PointSize,
    GetDocument()->m_PointList[i].x + GetDocument()->m_PointSize,
    GetDocument()->m_PointList[i].y + GetDocument()->m_PointSize);
    }
    }
    //
    void CDocumentView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject*
    /*pHint*/)
    {
    // TODO: Add your specialized code here and/or call the base class
    Invalidate();
    }

    But when i open a new document, it doesn't draw ellipse which is m_PointList , it shows a clean view window. And when i started to click also it doesn't change the other views. Where am i wrong?

    S N 2 Replies Last reply
    0
    • S sawerr

      Hi When clicks on View, my program draws ellipse and I tried to make all changes in one view reflects to all views. 1-)OnLbuttonDown adds a point to CArray m_PointList 2-)UpdateAllViews calls OnUpdate 3-) OnUpdate Invaliates so OnDraw called.

      void CDocumentView::OnLButtonDown(UINT nFlags, CPoint point)
      {
      GetDocument()->m_PointList.Add(point);
      GetDocument()->UpdateAllViews(NULL);

      CView::OnLButtonDown(nFlags, point);
      

      };
      //
      void CDocumentView::OnDraw(CDC* pDC)
      {
      CDocumentDoc* pDoc = GetDocument();
      ASSERT_VALID(pDoc);
      if (!pDoc)
      return;
      for(int i = 0; i < GetDocument()->m_PointList.GetCount(); i++)
      {
      pDC->Ellipse(GetDocument()->m_PointList[i].x - GetDocument()->m_PointSize,
      GetDocument()->m_PointList[i].y - GetDocument()->m_PointSize,
      GetDocument()->m_PointList[i].x + GetDocument()->m_PointSize,
      GetDocument()->m_PointList[i].y + GetDocument()->m_PointSize);
      }
      }
      //
      void CDocumentView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject*
      /*pHint*/)
      {
      // TODO: Add your specialized code here and/or call the base class
      Invalidate();
      }

      But when i open a new document, it doesn't draw ellipse which is m_PointList , it shows a clean view window. And when i started to click also it doesn't change the other views. Where am i wrong?

      S Offline
      S Offline
      SandipG
      wrote on last edited by
      #2

      If you open a new dicument contents of m_PointList will be changed ,isn't it? because you will be having new docuemnt class pointer.

      Regards, Sandip.

      S 1 Reply Last reply
      0
      • S SandipG

        If you open a new dicument contents of m_PointList will be changed ,isn't it? because you will be having new docuemnt class pointer.

        Regards, Sandip.

        S Offline
        S Offline
        sawerr
        wrote on last edited by
        #3

        Sorry; When i clicked File->New (Ctrl+N). My CArray m_PointList is in the document file (DocumentDoc.h). For every new view, same doc file using, right? Same m_PointList? But something wrong and i can't find it.

        S 1 Reply Last reply
        0
        • S sawerr

          Sorry; When i clicked File->New (Ctrl+N). My CArray m_PointList is in the document file (DocumentDoc.h). For every new view, same doc file using, right? Same m_PointList? But something wrong and i can't find it.

          S Offline
          S Offline
          SandipG
          wrote on last edited by
          #4

          its not about using same document.h file. everytime new instance of CDocuemnt will be created when you do ctrl+N so every time m_PointList will have default values.

          Regards, Sandip.

          S 1 Reply Last reply
          0
          • S SandipG

            its not about using same document.h file. everytime new instance of CDocuemnt will be created when you do ctrl+N so every time m_PointList will have default values.

            Regards, Sandip.

            S Offline
            S Offline
            sawerr
            wrote on last edited by
            #5

            What? If so, But why do we call updateallviews? Isn't that for all the views that created with Ctr+N? Isn't that advantage of Doc/View architecture, One Document and multiple views? I am really surprised.

            S 1 Reply Last reply
            0
            • S sawerr

              What? If so, But why do we call updateallviews? Isn't that for all the views that created with Ctr+N? Isn't that advantage of Doc/View architecture, One Document and multiple views? I am really surprised.

              S Offline
              S Offline
              SandipG
              wrote on last edited by
              #6

              Listen UpdateAllView is for updating All views associated with one instance of document. (not the views associated with different instances of documents.) Consider TreeView1 ListView1 both are associated to docuemnt1. Now when you call UpdateAllViews for docuement1 then Treeview1 and listview1 will be updated.

              Regards, Sandip.

              1 Reply Last reply
              0
              • S sawerr

                Hi When clicks on View, my program draws ellipse and I tried to make all changes in one view reflects to all views. 1-)OnLbuttonDown adds a point to CArray m_PointList 2-)UpdateAllViews calls OnUpdate 3-) OnUpdate Invaliates so OnDraw called.

                void CDocumentView::OnLButtonDown(UINT nFlags, CPoint point)
                {
                GetDocument()->m_PointList.Add(point);
                GetDocument()->UpdateAllViews(NULL);

                CView::OnLButtonDown(nFlags, point);
                

                };
                //
                void CDocumentView::OnDraw(CDC* pDC)
                {
                CDocumentDoc* pDoc = GetDocument();
                ASSERT_VALID(pDoc);
                if (!pDoc)
                return;
                for(int i = 0; i < GetDocument()->m_PointList.GetCount(); i++)
                {
                pDC->Ellipse(GetDocument()->m_PointList[i].x - GetDocument()->m_PointSize,
                GetDocument()->m_PointList[i].y - GetDocument()->m_PointSize,
                GetDocument()->m_PointList[i].x + GetDocument()->m_PointSize,
                GetDocument()->m_PointList[i].y + GetDocument()->m_PointSize);
                }
                }
                //
                void CDocumentView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject*
                /*pHint*/)
                {
                // TODO: Add your specialized code here and/or call the base class
                Invalidate();
                }

                But when i open a new document, it doesn't draw ellipse which is m_PointList , it shows a clean view window. And when i started to click also it doesn't change the other views. Where am i wrong?

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

                I agree with Sandi, you are creating new documents, so you will have new pairs Doc-View and the new ones have nothing to do with the old ones. If you DO want to have only one document and more views... take a look here[^]

                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 “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson 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