BOOL CSDIApp::InitInstance()
{
..............
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
///CSingleDocTemplate构造函数中
CSingleDocTemplate::CSingleDocTemplate(UINT nIDResource,
CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass,
CRuntimeClass* pViewClass)
: CDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass)
{
m_pOnlyDoc = NULL;
}
调用了基类的CDocTemplate构造函数
CDocTemplate::CDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass)
{
ASSERT_VALID_IDR(nIDResource);
ASSERT(pDocClass == NULL ||
pDocClass->IsDerivedFrom(RUNTIME_CLASS(CDocument)));
ASSERT(pFrameClass == NULL ||
pFrameClass->IsDerivedFrom(RUNTIME_CLASS(CFrameWnd)));
ASSERT(pViewClass == NULL ||
pViewClass->IsDerivedFrom(RUNTIME_CLASS(CView)));
m_nIDResource = nIDResource;
m_nIDServerResource = NULL;
m_nIDEmbeddingResource = NULL;
m_nIDContainerResource = NULL;
m_pDocClass = pDocClass;//文档对像
m_pFrameClass = pFrameClass;//框架对像
m_pViewClass = pViewClass;//视图对像
m_pOleFrameClass = NULL;
m_pOleViewClass = NULL;
m_pAttachedFactory = NULL;
m_hMenuInPlace = NULL;
m_hAccelInPlace = NULL;
m_hMenuEmbedding = NULL;
m_hAccelEmbedding = NULL;
m_hMenuInPlaceServer = NULL;
m_hAccelInPlaceServer = NULL;
// add to pStaticList if constructed as static instead of on heap
if (CDocManager::bStaticInit)
{
m_bAutoDelete = FALSE;
if (CDocManager::pStaticList == NULL)
CDocManager::pStaticList = new CPtrList;
if (CDocManager::pStaticDocManager == NULL)
CDocManager::pStaticDocManager = new CDocManager;
CDocManager::pStaticList->AddTail(this);
}
else
{
m_bAutoDelete = TRUE; // usually allocated on the heap
LoadTemplate();
}
}
在AfxWinMain函数中
pApp->InitApplication()将CDocManager::bStaticInit设为FALSE
LoadTemplate()函数代码如下,加载字符串字源
m_strDocStrings.LoadString(m_nIDResource)
void CDocTem
SDI单文档的启动过程
最新推荐文章于 2022-07-30 20:46:18 发布
本文详细介绍了SDI(单文档界面)应用程序的启动过程,包括CSDIApp::InitInstance()函数的执行,如何使用CSingleDocTemplate创建文档模板,以及如何处理命令行参数来打开新文档。在CWinApp的生命周期中,涉及到文档和框架窗口的创建,如CreateNewDocument()和CreateNewFrame(),以及OnFileNew()和OpenDocumentFile(NULL)的调用来创建新的文档实例。整个过程涉及到了C++ MFC框架下的多个类和方法,如CDocTemplate、CFrameWnd和CView的交互,展示了MFC如何管理SDI应用的文档、视图和框架窗口的创建。
摘要由CSDN通过智能技术生成