CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: UpdateAllViews

  1. #1
    Join Date
    Sep 2005
    Posts
    336

    UpdateAllViews

    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.
    Code:
    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?

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: UpdateAllViews

    You have to explain a little bit about your architecture. What is CDocumentView?

    In a doc/view architecture, you should keep the data in the document, and display it from the associated view(s).

    When you use the new document command, you obviously create a new document, so of course it does not know anything about the points you added to other documents. I think that what you are trying to do is creating a new view an already opened document, but you have to clarify this before we could go forward.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Sep 2005
    Posts
    336

    Re: UpdateAllViews

    Sorry.
    My (quick) project name is Document
    Document: DocumentDoc.h and .cpp
    View: DocumentView.h and .cpp

    And also i have a Dialog which takes size of the point and store it in m_PointSize which is in CDocumentDoc.

    My variables are in CDocumentDoc and my program gets it from Document and show it in CDocumentView.

    It can show points also can change size of points.

    But when i open a new view window with CTR+N. It doesn't reflect to new window. There is no point in new window. But i assumed that creating new window means it calls draw method so it would show all the points which is showed also in other view.

    In Doc/View arc. there is one document and multipleviews so i called UpdateAllViews as seen above. But new child windows can't show it. It seems that i can't relate views through doc.

    I hope i can explain now.
    Thanks.
    Last edited by sawer; June 2nd, 2008 at 07:29 AM.

  4. #4
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: UpdateAllViews

    If this is an MDI project, there can be multiple documents created. Each time you do a New (Ctrl-N) a new document is created unless you override the default behavior.

    If you use SDI, then there is only one document, but a File->New will call the documents DeleteContents function, allowing you to clean out the current document and make it look like a new one. If you don't override the DeleteContents, the your document would still contain what it had before.

    Hope that helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  5. #5
    Join Date
    Sep 2005
    Posts
    336

    Re: UpdateAllViews

    Thanks krmed;
    Yes MDI project.
    How can i override the default behavior?

  6. #6
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: UpdateAllViews

    See OnFileNew in MSDN.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: UpdateAllViews

    OK, as Marius (cilu) has already mentioned, when you invoke File New command new view is created. In MDI application document manager creates new instances of the frame, view and document, hence no previous data is displayed since there is no data.

    The only way to retain data is to save it and you are responsible to write a code to do so, possibly using serialization dunctionality of the document.

    Then you can use File Open. This command will also crete new instances of frame, view and document but in addition serialization routine will be called allowing you to read data from previously saved file.

    Why don’t you try to follow a MFC tutorial: Scribble?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured