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