MFC窗口创建过程

本文针对单文档模式的MFC程序进行分析。一步步说明,如何创建窗口并显示。

首先我们创建一个单文档的MFC程序:Test。

1:打开CTestApp::InitInstance(),可以看到

CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CTestDoc),
RUNTIME_CLASS(CMainFrame),       // main SDI frame window
RUNTIME_CLASS(CTestView));
AddDocTemplate(pDocTemplate);


// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
  

首先创建了一个单文档的模板,并且添加到模板管理器。

真正的创建窗口在ProcessShellCommand(cmdInfo),追踪CWinApp::ProcessShellCommand(cmdInfo) 可以看到调用了CWinApp::OpenDocumentFile

而在CWinApp::OpenDocumentFile中有调用了 m_pDocManager->OpenDocumentFile(lpszFileName); 

通过文档模板管理器,绝对调用哪个模板的  return pBestTemplate->OpenDocumentFile(szPath);

这里是单文档,因此调用了单文档模板 CSingleDocTemplate::OpenDocumentFile 。

在 CSingleDocTemplate::OpenDocumentFile 中,继续可以看到   pFrame = CreateNewFrame(pDocument, NULL);

继续追踪  CDocTemplate::CreateNewFrame 则有    pFrame->LoadFrame(m_nIDResource,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,NULL, &context)

这里调用了CFrameWnd::LoadFrame,而 CFrameWnd::LoadFrame 调用  

 CFrameWnd::Create 
  创建窗口。

但是真正的创建窗口的动作在 CWnd::CreateEx 中。因此可以看到 CWnd::CreateEx 被  CFrameWnd::Create 调用。


只有显示窗口则在CTestApp::InitInstance 中的

m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
 来完成。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值