MFC文档视图结构框架分析(5)

2019-03-09 22:08

{

TRACE0(\未能创建工具栏\\n\ return -1; // 未能创建 }

if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) {

TRACE0(\未能创建状态栏\\n\ return -1; // 未能创建 }

//TODO: 如果不需要工具栏可停靠,则删除这三行 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar);

return 0; }

5:运行后为什么能产生CMainFarme,文档 ,视图以及视图外包围的farme呢?

你注意过吗,当我们一点运行,会默认出来一个视图窗口,这是谁调用的呢?哦,就是下面这几行,它调用void CWinApp::OnFileNew()函数.

CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo);

if (!ProcessShellCommand(cmdInfo)) return FALSE;

你可以自己跟踪以下。这里有个小技巧,你可以在BOOL CmyDoc::OnNewDocument()处设立断点,然后“跳出”,最后你会达到起始点!ProcessShellCommand(cmdInfo)

void CWinApp::OnFileNew() {

if (m_pDocManager != NULL)

m_pDocManager->OnFileNew(); //接着调用下面的函数 }

void CDocManager::OnFileNew() {

if (m_templateList.IsEmpty()) {

TRACE(traceAppMsg, 0, \ CWinApp.\\n\

AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC); return; }

CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetHead(); if (m_templateList.GetCount() > 1) {

// more than one document template to choose from // bring up dialog prompting user CNewTypeDlg dlg(&m_templateList); INT_PTR nID = dlg.DoModal(); if (nID == IDOK)

pTemplate = dlg.m_pSelectedTemplate; else

return; // none - cancel operation }

ASSERT(pTemplate != NULL);

ASSERT_KINDOF(CDocTemplate, pTemplate);

pTemplate->OpenDocumentFile(NULL); //接着调用下面的函数

// if returns NULL, the user has already been alerted }

CDocument* CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible) {

CDocument* pDocument = CreateNewDocument(); //产生模板控制之一:文档 if (pDocument == NULL) {

TRACE(traceAppMsg, 0, \L.\\n\

AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC); return NULL; }

ASSERT_VALID(pDocument);

BOOL bAutoDelete = pDocument->m_bAutoDelete;

pDocument->m_bAutoDelete = FALSE; // don't destroy if something goes wrong

CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL); //产生新的:框架

pDocument->m_bAutoDelete = bAutoDelete; if (pFrame == NULL) {

AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC); delete pDocument; // explicit delete on error return NULL; }

ASSERT_VALID(pFrame);

if (lpszPathName == NULL)

{

// create a new document - with default document name SetDefaultTitle(pDocument);

// avoid creating 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, \\\n\

pFrame->DestroyWindow(); return NULL; }

// it worked, now bump untitled count m_nUntitledCount++; } else {

// open an existing document CWaitCursor wait;

if (!pDocument->OnOpenDocument(lpszPathName)) {

// user has be alerted to what failed in OnOpenDocument

TRACE(traceAppMsg, 0, \\\n\

pFrame->DestroyWindow();

return NULL; }

pDocument->SetPathName(lpszPathName); }

InitialUpdateFrame(pFrame, pDocument, bMakeVisible); return pDocument; }

我需要对上述函数进行进一步说明

(1)CreateNewDocument()产生文档

CDocument* CDocTemplate::CreateNewDocument() {

// default implementation constructs one from CRuntimeClass if (m_pDocClass == NULL) {

TRACE(traceAppMsg, 0, \eNewDocument.\\n\

ASSERT(FALSE); return NULL; }

CDocument* pDocument = (CDocument*)m_pDocClass->CreateObject(); if (pDocument == NULL) {

TRACE(traceAppMsg, 0, \ failed.\\n\

m_pDocClass->m_lpszClassName); return NULL;

}

ASSERT_KINDOF(CDocument, pDocument); AddDocument(pDocument); return pDocument; }

(2)CreateNewFrame(pDocument, NULL),产生框架和视图

CFrameWnd* CDocTemplate::CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther)

{

if (pDoc != NULL) ASSERT_VALID(pDoc);

// create a frame wired to the specified document

ASSERT(m_nIDResource != 0); // must have a resource ID to load from CCreateContext context;

context.m_pCurrentFrame = pOther;


MFC文档视图结构框架分析(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017会计硕士考研备考研习:英语词汇强化练习题(四)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: