Click here to Skip to main content
15,886,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

Im implementing serialization in the document/view architecture. In that im drawing multiple lines using mouse click event.

C#
void CserializationTestDoc::Serialize(CArchive& ar)
{
    CserializationTestView s;
    if (ar.IsStoring())
    {
        // TODO: add storing code here
        ar<<s.l[0]<<s.l[1]<<s.PtLine;
    }
    else
    {
        // TODO: add loading code here
        ar>>s.l[0]>>s.l[1]>>s.PtLine;
    }
}


Here l[0],l[1] and PtLine are the variables which containing the values of points to draw the lines. Is that enough to include the variables in the serialize function in the document class. In the else statement how to call the OnDraw function.

Thankyou,
Posted
Updated 10-Dec-12 1:27am
v4
Comments
Richard MacCutchan 10-Dec-12 4:38am    
Assuming that is all the data in your document then yes, that should be enough. However, I suspect there is a lot more data somewhere that you are not showing.
J.Surjith Kumar 10-Dec-12 5:10am    
Im using that variables in the view class..

void CserializationTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
l[0]=point.x;
l[1]=point.y;
flag=1;
CView::OnLButtonDown(nFlags, point);
}

void CserializationTestView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
PtLine=CPoint(point.x,point.y);
/*if(flag==1)
{
dc.MoveTo(l[0],l[1]);
dc.LineTo(PtLine);
}*/
Invalidate();
CView::OnLButtonUp(nFlags, point);
}

void CserializationTestView::OnDraw(CDC* pDC)
{
CserializationTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->MoveTo(l[0],l[1]);
pDC->LineTo(PtLine);

// TODO: add draw code for native data here
}
J.Surjith Kumar 10-Dec-12 5:12am    
There is no error but the value of that variable was not retrieved when i open the file.
J.Surjith Kumar 10-Dec-12 6:15am    
How the serialize function knows that the object ar is for storing or loading. Can u explain how it works internally in the doc/view architecture without creating the CFile object and CArchive object.
Richard MacCutchan 10-Dec-12 9:39am    
The documentation for CArchive explains how it works and how you should implement it. One thing you should look at is your basic design here; you should not be mixing your serialization and drawing code in the same places. The MFC SDI template is based on the MVC model, the idea being that you separate the manipulation of your data from its display. Your serialization code should be inside your CDocument class, and your drawing code should be inside your view's OnDraw() method.

I am sure that I have explained this to you more than once already. Are you sure you are not posting the same questions under a different CodeProject name?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900