MFC 的MDI创建空文档调用过程
2017-10-13 22:03
337 查看
1,XXApp类中的消息映射
ON_COMMAND(ID_FILE_NEW,
CWinAppEx::OnFileNew)
2,
void CWinApp::OnFileNew()
{
if(m_pDocManager != NULL)
m_pDocManager->OnFileNew();
}
3,
void CDocManager::OnFileNew()
{
if(m_templateList.IsEmpty())
{
TRACE(traceAppMsg, 0, "Error: no document templates registered withCWinApp.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return;
}
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetHead();
if (m_templateList.GetCount()> 1)
{
// morethan one document template to choose from
// 超过一个doctemplate出现对话框让用户选择
CNewTypeDlg dlg(&m_templateList);
INT_PTR nID = dlg.DoModal();
if(nID == IDOK)
pTemplate =dlg.m_pSelectedTemplate;
else
return;
// none - canceloperation
}
ASSERT(pTemplate != NULL);
ASSERT_KINDOF(CDocTemplate, pTemplate);
pTemplate->OpenDocumentFile(NULL);
// ifreturns NULL, the user has already been alerted
}
4,
CDocument*CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bAddToMRU, BOOLbMakeVisible)
{
CDocument* pDocument = CreateNewDocument(); 创建Doc类对象
if(pDocument == NULL)
{
TRACE(traceAppMsg, 0, "CDocTemplate::CreateNewDocument returnedNULL.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
returnNULL;
}
ASSERT_VALID(pDocument);
BOOL bAutoDelete =pDocument->m_bAutoDelete;
pDocument->m_bAutoDelete = FALSE;
// don't destroyif something goes wrong
CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL); 创建ChildFrame和View对象
pDocument->m_bAutoDelete = bAutoDelete;
if(pFrame == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
deletepDocument;
//explicit delete on error
returnNULL;
}
ASSERT_VALID(pFrame);
if(lpszPathName == NULL)
{
//create a new document - with default document name
SetDefaultTitle(pDocument);
// avoidcreating temporary compound file when starting up invisible
if(!bMakeVisible)
pDocument->m_bEmbedded =TRUE;
if(!pDocument->OnNewDocument())虚函数
{
//user has be alerted to what failed in OnNewDocument
TRACE(traceAppMsg, 0,
"CDocument::OnNewDocument returned FALSE.\n");
pFrame->DestroyWindow();
returnNULL;
}
// itworked, now bump untitled count
m_nUntitledCount++;
}
else
{
// openan existing document
CWaitCursor wait;
if(!pDocument->OnOpenDocument(lpszPathName))
{
//user has be alerted to what failed in OnOpenDocument
TRACE(traceAppMsg, 0,
"CDocument::OnOpenDocument returned FALSE.\n");
pFrame->DestroyWindow();
returnNULL;
}
pDocument->SetPathName(lpszPathName,bAddToMRU);
pDocument->OnDocumentEvent(CDocument::onAfterOpenDocument);
}
InitialUpdateFrame(pFrame, pDocument,bMakeVisible);
return pDocument;
}
ON_COMMAND(ID_FILE_NEW,
CWinAppEx::OnFileNew)
2,
void CWinApp::OnFileNew()
{
if(m_pDocManager != NULL)
m_pDocManager->OnFileNew();
}
3,
void CDocManager::OnFileNew()
{
if(m_templateList.IsEmpty())
{
TRACE(traceAppMsg, 0, "Error: no document templates registered withCWinApp.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return;
}
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetHead();
if (m_templateList.GetCount()> 1)
{
// morethan one document template to choose from
// 超过一个doctemplate出现对话框让用户选择
CNewTypeDlg dlg(&m_templateList);
INT_PTR nID = dlg.DoModal();
if(nID == IDOK)
pTemplate =dlg.m_pSelectedTemplate;
else
return;
// none - canceloperation
}
ASSERT(pTemplate != NULL);
ASSERT_KINDOF(CDocTemplate, pTemplate);
pTemplate->OpenDocumentFile(NULL);
// ifreturns NULL, the user has already been alerted
}
4,
CDocument*CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bAddToMRU, BOOLbMakeVisible)
{
CDocument* pDocument = CreateNewDocument(); 创建Doc类对象
if(pDocument == NULL)
{
TRACE(traceAppMsg, 0, "CDocTemplate::CreateNewDocument returnedNULL.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
returnNULL;
}
ASSERT_VALID(pDocument);
BOOL bAutoDelete =pDocument->m_bAutoDelete;
pDocument->m_bAutoDelete = FALSE;
// don't destroyif something goes wrong
CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL); 创建ChildFrame和View对象
pDocument->m_bAutoDelete = bAutoDelete;
if(pFrame == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
deletepDocument;
//explicit delete on error
returnNULL;
}
ASSERT_VALID(pFrame);
if(lpszPathName == NULL)
{
//create a new document - with default document name
SetDefaultTitle(pDocument);
// avoidcreating temporary compound file when starting up invisible
if(!bMakeVisible)
pDocument->m_bEmbedded =TRUE;
if(!pDocument->OnNewDocument())虚函数
{
//user has be alerted to what failed in OnNewDocument
TRACE(traceAppMsg, 0,
"CDocument::OnNewDocument returned FALSE.\n");
pFrame->DestroyWindow();
returnNULL;
}
// itworked, now bump untitled count
m_nUntitledCount++;
}
else
{
// openan existing document
CWaitCursor wait;
if(!pDocument->OnOpenDocument(lpszPathName))
{
//user has be alerted to what failed in OnOpenDocument
TRACE(traceAppMsg, 0,
"CDocument::OnOpenDocument returned FALSE.\n");
pFrame->DestroyWindow();
returnNULL;
}
pDocument->SetPathName(lpszPathName,bAddToMRU);
pDocument->OnDocumentEvent(CDocument::onAfterOpenDocument);
}
InitialUpdateFrame(pFrame, pDocument,bMakeVisible);
return pDocument;
}
相关文章推荐
- MDI程序系统框架单文档对应多视图 切换 创建实现过程。
- MFC应用程序中处理消息,创建窗口的过程,关闭窗口(非模态窗口),打开模式对话框等的函数调用顺序 .
- MFC应用程序中处理消息的顺序,创建窗口的过程关闭窗口的顺序(非模态窗口),打开模式对话框的函数调用顺序
- MFC应用程序消息处理及其窗口创建和销毁过程函数调用顺序
- MFC 单文档创建过程
- MFC MDI使用自定义模板对话框创建子文档
- MFC应用程序中处理消息的顺序,创建窗口的过程关闭窗口的顺序(非模态窗口),打开模式对话框的函数调用顺序
- MFC应用程序消息处理及其窗口创建和销毁过程函数调用顺序
- MFC创建的MDI程序 新建一个子文档 主窗口标题自动会被追加上子文档的名字 取消此功能
- MFC应用程序消息处理及其窗口创建和销毁过程函数调用顺序
- MFC应用程序中处理消息的顺序,创建窗口的过程关闭窗口的顺序(非模态窗口),打开模式对话框的函数调用顺序
- MFC应用程序中处理消息的顺序,创建窗口的过程关闭窗口的顺序(非模态窗口),打开模式对话框的函数调用顺序
- MFC应用程序消息处理及其窗口创建和销毁过程函数调用顺序
- MFC多文档的创建和打开过程
- MFC MDI多文档工具栏浮动提示添加方法
- 【原】备忘:Oracle 中创建存储过程及调用测试一例
- 深入剖析MFC基础框架——跟踪MFC单文档程序的执行过程:
- 创建无边框的MFC单文档(SDI)应用程序
- 一种限制MFC MDI架构中某类型文档个数的方法
- 学习MFC框架如何创建的过程