[ Home | Syllabus | Course Notes | Assignments | Search]
This example illustrates the following features of document/view (source code here)
#ifdef _DEBUG
void CStudent::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
dc << "m_strName = " << m_strName << "\nm_nGrade = " << m_nGrade;
}
#endif // _DEBUG
Will be a data member of the Document object
BOOL CEx16aDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// (SDI documents will reuse this document)
m_student = CStudent("default value", 0); // added to fix non reset on File/New
return TRUE;
}
void CEx16aView::OnInitialUpdate()
{ // called on startup
UpdateControlsFromDoc();
}
// all action is here
void CEx16aView::UpdateControlsFromDoc()
{ // called from OnInitialUpdate and OnEditClearAll
CEx16aDoc* pDoc = GetDocument();
m_nGrade = pDoc->m_student.m_nGrade;
m_strName = pDoc->m_student.m_strName;
UpdateData(FALSE); // calls DDX
}
void CEx16aView::OnEnter()
{
CEx16aDoc* pDoc = GetDocument();
UpdateData(TRUE);
pDoc->m_student.m_nGrade = m_nGrade;
pDoc->m_student.m_strName = m_strName;
}
void CStudent::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << m_strName << m_nGrade;
}
else
{
ar >> m_strName >> m_nGrade;
}
}
void CEx16aDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
m_student.Serialize(ar);
}
else
{
m_student.Serialize(ar);
}
}