做为 CWinApp 的派生类,通常需要重载 InitInstance(), ExitInstance()
两个函数,以完成应用的初始化和退出。我们现在关心 InitInstance 中关于文
档模板、窗口处理的部分,而忽略掉一些 CommonControl, OLE 初始化部分。
整个 InitInstance 代码如下:
BOOL CMDITestApp::InitInstance()
{
InitCommonControls(); // 这里删减了大量注释和错误处理
CWinApp::InitInstance();
AfxOleInit();
AfxEnableControlContainer();
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU)
TRACE("Before CMultiDocTemplate\n");
// 注册应用程序的文档模板。文档模板
// 将用作文档、框架窗口和视图之间的连接
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_MDITestTYPE,
RUNTIME_CLASS(CMDITestDoc),
RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
RUNTIME_CLASS(CMDITestView));
if (!pDocTemplate)
return FALSE;
TRACE("Before AddDocTemplate\n");
AddDocTemplate(pDocTemplate);
// 创建主 MDI 框架窗口
TRACE("Before new CMainFrame\n");
CMainFrame* pMainFrame = new CMainFrame;
TRACE("Before pMainFrame->LoadFrame\n");
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
TRACE("Before ParseCommandLine\n");
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// 调度在命令行中指定的命令。如果
// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
TRACE("Before ProcessShellCommand\n");
if (!ProcessShellCommand(cmdInfo))
return FALSE;
评论0