SDI单文档的启动过程

本文详细介绍了SDI(单文档界面)应用程序的启动过程,包括CSDIApp::InitInstance()函数的执行,如何使用CSingleDocTemplate创建文档模板,以及如何处理命令行参数来打开新文档。在CWinApp的生命周期中,涉及到文档和框架窗口的创建,如CreateNewDocument()和CreateNewFrame(),以及OnFileNew()和OpenDocumentFile(NULL)的调用来创建新的文档实例。整个过程涉及到了C++ MFC框架下的多个类和方法,如CDocTemplate、CFrameWnd和CView的交互,展示了MFC如何管理SDI应用的文档、视图和框架窗口的创建。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值