按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
CDocument* CWinApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
{
ASSERT(m_pDocManager != NULL);
ASSERT(m_pDocManager != NULL);
return m_pDocManager…》OpenDocumentFile (lpszFileName);
return m_pDocManager…》OpenDocumentFile (lpszFileName);
}
}
很多原先在CWinApp 中做掉的有关于Document
Template 的工作,如AddDocTemplate、
OpenDocumentFile 和NewDocumentFile,自从
MFC 4。0 之后已隔离出来由CDocManager 负责。
CDocument* CDocManager::OpenDocumentFile(LPCTSTR lpszFileName)
{
// find the highest confidence
CDocTemplate* pBestTemplate = NULL;
CDocument* pOpenDocument = NULL;
TCHAR szPath'_MAX_PATH';
。。。 //从「Document Template 串行」中找出最适当之template,
。。。 //放到pBestTemplate 中。
return pBestTemplate…》OpenDocumentFile (szPath);
}
由于CMultiDocTemplate改写了OpenDocumentFile;所以调用
的是CMultiDocTemplate::OpenDocumentFile。
下页
516
…………………………………………………………Page 579……………………………………………………………
第8章 Document…View 深入探討
CDocument* CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName;
BOOL bMakeVisible)
{
CDocument* pDocument = CreateNewDocument();
。。。
CFrameWnd* pFrame = CreateNewFrame(pDocument; NULL);
。。。
由于CScribbleDoc 改写了OnOpenDocument,
if (lpszPathName == NULL) 所以调用的是CScribbleDoc::OnOpenDocument
{
// create a new document with default document name
。。。
}
else
{
// open an existing document
CWaitCursor wait;
if (!pDocument…》OnOpenDocument (lpszPathName))
{ 源代码请见本章前部之“CDocTemplate管理
。。。
CDocument/CView/CFrameWnd” 一节.
}
pDocument…》SetPathName(lpszPathName);
BOOL CScribbleDoc::OnOpenDocument(LPCTSTR lpszPathName)
} {BOOL CScribbleDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument (lpszPathName))
if (!CDocument::OnOpenDocument (lpszPathName))
return FALSE;
return FALSE;
InitDocument();
InitDocument();
return TRUE;
return TRUE;
}
}
InitialUpdateFrame(pFrame; pDocument; bMakeVisible);
return pDocument;
}
下页
517
…………………………………………………………Page 580……………………………………………………………
第篇 深入 MFC 程式設計
BOOL CDocument::OnOpenDocument(LPCTSTR lpszPathName)
{
CFileException fe;
CFile* pFile = GetFile(lpszPathName;
CFile::modeRead|CFile::shareDenyWrite; &fe);
DeleteContents();
SetModifiedFlag(); // dirty during de…serialize
CArchive loadArchive (pFile; CArchive::load |
CArchive::bNoFlushOnDelete);
loadArchive。m_pDocument = this;
loadArchive。m_bForceFlat = FALSE;
TRY
{
CWaitCursor wait;
if (pFile…》GetLength() != 0)
Serialize(loadArchive); // load me
loadArchive。Close(); 由于 Serialize
CScribbleDoc 改写了
ReleaseFile(pFile; FALSE); 所以调用的是CScribbleDoc::Serialize
}
。。。 void CScribbleDoc::Serialize(CArchive& ar)
} void CScribbleDoc::Serialize(CArchive& ar)
{
{
。。。
。。。
m_strokeList。Serialize (ar);
m_strokeList。Serialize (ar);
}
}
void CObList::Serialize(CArchive& ar)
{
CObject::Serialize(ar);
if (ar。IsStoring())
{
。。。
}
else 本例读入 0004
{
DWORD nNewCount = ar。ReadCount();
CObject* newData;
while (nNewCount……)
{
for