深入浅出MFC“文档/视图”架构(3)――文档
2009-02-11 20:00:34 来源:WEB开发网保存文档的函数CDocument::OnSaveDocument完成的工作包括如下几步:
(1)创建或打开文件对象;
(2)建立相对应的CArchive对象;
(3)调用应用程序文档对象的序列化函数Serialize();
(4)关闭文件对象、CArchive对象;
(5)设置文件未修改标志。
void CDocument::OnCloseDocument()
// must close all views now (no prompting) - usually destroys this
{
// destroy all frames viewing this document
// the last destroy may destroy us
BOOL bAutoDelete = m_bAutoDelete;
m_bAutoDelete = FALSE; // don't destroy document while closing views
while (!m_viewList.IsEmpty())
{
// get frame attached to the view
CView* pView = (CView*)m_viewList.GetHead();
ASSERT_VALID(pView);
CFrameWnd* pFrame = pView->GetParentFrame();
ASSERT_VALID(pFrame);
// and close it
PreCloseFrame(pFrame);
pFrame->DestroyWindow();
// will destroy the view as well
}
m_bAutoDelete = bAutoDelete;
// clean up contents of document before destroying the document itself
DeleteContents();
// delete the document if necessary
if (m_bAutoDelete)
delete this;
}
更多精彩
赞助商链接