陈国坤上过的节目:学习MFC框架如何创建的过程.CWnd::ProcessShellCommand.下部
来源:百度文库 编辑:九乡新闻网 时间:2024/04/27 16:25:25
系列快速导航:三要点
1、 CDocTemplate 学习MFC框架如何创建的过程.CDocTemplate
2、 CFrameWnd::LoadFrame 学习MFC框架如何创建的过程.LoadFrame
3、 CWnd::ProcessShellCommand
学习MFC框架如何创建的过程.CWnd::ProcessShellCommand.上部
学习MFC框架如何创建的过程.CWnd::ProcessShellCommand.下部
CMDITestDoc有如下的定义,仅能从CRuntimeClass里面创建的。
class CMDITestDoc : public CDocument
{
protected: // 仅从序列化创建
CMDITestDoc(); // 被保护的构造函数
DECLARE_DYNCREATE(CMDITestDoc) // 支持从 CRuntimeClass 信息中创建。
再接着进行CreateNewFrame。
CFrameWnd* CDocTemplate::CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther)
{
// create a frame wired to the specified document
CCreateContext context; // 这个 CreateContext 传递到 LoadFrame 中
context.m_pCurrentFrame = pOther; // 此例中 = NULL
context.m_pCurrentDoc = pDoc; // = 刚才创建的文档
context.m_pNewViewClass = m_pViewClass; // 显示此文档的视类的类型
context.m_pNewDocTemplate = this;
if (m_pFrameClass == NULL)
// 提示错误并返回
// 利用 CRuntimeClass 信息创建框架窗口对象,此例中为 CChildFrame
CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass->CreateObject();
// 这里,我们又看到了 LoadFrame , 参考前面的 LoadFrame 吧
// 在这里面,View 窗口也被产生出来。参考 TRACE 输出。
pFrame->LoadFrame(m_nIDResource,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, // default frame styles
NULL, &context);
return pFrame;
}
LoadFrame之后View窗口将被创建出来,接着进入到CMDITestDoc::OnNewDocument中,现在仅仅是一个空的函数,没有特定代码。
BOOL CMDITestDoc::OnNewDocument()
{
TRACE("CMDITestDoc::OnNewDocument() entry\n");
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: 在此添加重新初始化代码
// (SDI 文档将重用该文档)
return TRUE;
}
最后是CDocTemplate::InitialUpdateFrame,这里面主要是激活新建的框架、文档、视,看得挺头疼的。
void CDocTemplate::InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc,
BOOL bMakeVisible)
{
// just delagate to implementation in CFrameWnd
pFrame->InitialUpdateFrame(pDoc, bMakeVisible);
}
现在,文档、框架窗口、视窗口全部被创建出来,我们胜利的返回到ProcessShellCommand处。显示和更新主窗口,完成了WinApp::InitInstance :
// 主窗口已初始化,因此显示它并对其进行更新
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
看一下至此的TRACE输出,中间的DLL加载被去掉了:
Before CMultiDocTemplate
Before AddDocTemplate
Before new CMainFrame
CMainFrame::CMainFrame()
Before pMainFrame->LoadFrame
CMainFrame::PreCreateWindow entry // 注意:PreCreateWindow 被两次调用
CMainFrame::PreCreateWindow entry
CMainFrame::OnCreate entry before CMDIFrameWnd::OnCreate
CMainFrame::OnCreate before m_wndToolBar.CreateEx
CMainFrame::OnCreate before m_wndStatusBar.Create
Before ParseCommandLine
Before ProcessShellCommand
CMDITestDoc::CMDITestDoc() // 文档对象被创建
CChildFrame::CChildFrame() // 子框架窗口被创建
CChildFrame::PreCreateWindow entry
CChildFrame::PreCreateWindow entry
CChildFrame::PreCreateWindow entry
CMDITestView::CMDITestView() entry // 子框架窗口的 OnCreate 中创建了 View 窗口
CMDITestView::PreCreateWindow entry
CMDITestDoc::OnNewDocument() entry
Before pMainFrame->ShowWindow
Before pMainFrame->UpdateWindow
// 退出时的 TRACE
CMDITestView::~CMDITestView()
CChildFrame::~CChildFrame()
CMDITestDoc::~CMDITestDoc()
CMainFrame::~CMainFrame()