GetDocString()
这个函数查找ID ==IDR_MAINFRAME string table当中的7个字符串。
CDocTemplate::windowTitle 主窗口标题,只出现在SDI程序。
CDocTemplate::docName 文档名称,设置成空的话====无标题
CDocTemplate::fileNewName 文件->新建 命令下的文档名称,会出现在文件对话框中
CDocTemplate::filterName 出现在文件->打开对话框 ,描述程序作者想筛选的文档类型,比如:文本文件(*.txt)
CDocTemplate::filterExt 文件对话框的扩展名,用于过滤文件,要配合 filterName使用,例子:.txt
CDocTemplate::regFileTypeId Identifier for the document type to be stored in the registration database maintained by Windows. This string is for internal use only (for example, “ExcelWorksheet”). If not specified, the document type cannot be registered with the Windows File Manager.
CDocTemplate::regFileTypeName Name of the document type to be stored in the registration database. This string may be displayed in dialog boxes of applications that access the registration database (for example, “Microsoft Excel Worksheet”).
文件->打开 的流程
1)CWinApp类首先响应
/*********
appdlg.cpp
*********/
void CWinApp::OnFileOpen()
{
ENSURE(m_pDocManager != NULL);
m_pDocManager->OnFileOpen();
}
2)转到CDocManger
弹出打开文件对话框并获取 filename
/**********
docmgr.cpp
***********/
void CDocManager::OnFileOpen()
{
CString newName;
if (!DoPromptFileName(newName, AFX_IDS_OPENFILE,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, NULL))
return; //调用这个函数弹出打开文件对话框 用newName保存用户选择的文件名
AfxGetApp()->OpenDocumentFile(newName);
}
3)转到CWinApp类
/****
appui.cpp
***/
CDocument* CWinApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
ENSURE_VALID(m_pDocManager);
return m_pDocManager->OpenDocumentFile(lpszFileName);
}
4)转到CDocManager类
CDocument* CDocManager::OpenDocumentFile(LPCTSTR lpszFileName)
{
return OpenDocumentFile(lpszFileName, TRUE);
}
CDocument* CDocManager::OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU)
{
if (lpszFileName == NULL)
{
AfxThrowInvalidArgException();
}
/*........省略............*/
return pBestTemplate->OpenDocumentFile(szPath, bAddToMRU, TRUE);//跳转到文档模板类
}
5)转到文档模板类
CDocument* CSingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bAddToMRU, BOOL bMakeVisible)
{
/********省略**********/
pDocument->OnOpenDocument(lpszPathName)
}
6)转到文档类 pDocument->OnOpenDocument(lpszPathName)
/**** doccore.cpp *****/
//在调用这个函数前我们有机会去自定义 文件对话框 然后传递LPCTSTR lpszPathName
BOOL CDocument::OnOpenDocument(LPCTSTR lpszPathName)
{
CFile* pFile = GetFile(lpszPathName,
CFile::modeRead|CFile::shareDenyWrite, pfe);
DeleteContents();//打开新文档,释放旧文档的内存空间
CArchive loadArchive(pFile, CArchive::load | CArchive::bNoFlushOnDelete);
loadArchive.m_pDocument = this;
loadArchive.m_bForceFlat = FALSE;
CWaitCursor wait;
if (pFile->GetLength() != 0)
Serialize(loadArchive); // 调用CDocument类的Serialize()函数
loadArchive.Close();
ReleaseFile(pFile, FALSE);
SetModifiedFlag(FALSE); // start off with unmodified
return TRUE;
}