CFrameWnd* CDocTemplate::CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther) { if (pDoc != NULL) ASSERT_VALID(pDoc); // create a frame wired to the specified document ASSERT(m_nIDResource != 0); // must have a resource ID to load from CCreateContext context; context.m_pCurrentFrame = pOther; context.m_pCurrentDoc = pDoc; context.m_pNewViewClass = m_pViewClass; context.m_pNewDocTemplate = this; if (m_pFrameClass == NULL) { TRACE0("Error: you must override CDocTemplate::CreateNewFrame.\n"); ASSERT(FALSE); return NULL; } CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass->CreateObject(); if (pFrame == NULL) { TRACE1("Warning: Dynamic create of frame %hs failed.\n", m_pFrameClass->m_lpszClassName); return NULL; } ASSERT_KINDOF(CFrameWnd, pFrame); if (context.m_pNewViewClass == NULL) TRACE0("Warning: creating frame with no default view.\n"); // create new from resource if (!pFrame->LoadFrame(m_nIDResource, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, // default frame styles NULL, &context)) { TRACE0("Warning: CDocTemplate couldn't create a frame.\n"); // frame will be deleted in PostNcDestroy cleanup return NULL; } // it worked ! return pFrame; }
从vs开发环境中建立的多文档程序架构,是这么调用的: CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_MFCVIETYPE, RUNTIME_CLASS(CMFCVIEWDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CMFCVIEWView)); AddDocTemplate(pDocTemplate); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) //在这里调用 return FALSE; m_pMainWnd = pMainFrame;也就是说在程序的InitInstance()函数里进行调用,其功能是建立CMDIFrameWnd窗口。
{
if (pDoc != NULL)
ASSERT_VALID(pDoc);
// create a frame wired to the specified document ASSERT(m_nIDResource != 0); // must have a resource ID to load from
CCreateContext context;
context.m_pCurrentFrame = pOther;
context.m_pCurrentDoc = pDoc;
context.m_pNewViewClass = m_pViewClass;
context.m_pNewDocTemplate = this; if (m_pFrameClass == NULL)
{
TRACE0("Error: you must override CDocTemplate::CreateNewFrame.\n");
ASSERT(FALSE);
return NULL;
}
CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass->CreateObject();
if (pFrame == NULL)
{
TRACE1("Warning: Dynamic create of frame %hs failed.\n",
m_pFrameClass->m_lpszClassName);
return NULL;
}
ASSERT_KINDOF(CFrameWnd, pFrame); if (context.m_pNewViewClass == NULL)
TRACE0("Warning: creating frame with no default view.\n"); // create new from resource
if (!pFrame->LoadFrame(m_nIDResource,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, // default frame styles
NULL, &context))
{
TRACE0("Warning: CDocTemplate couldn't create a frame.\n");
// frame will be deleted in PostNcDestroy cleanup
return NULL;
} // it worked !
return pFrame;
}
pDocTemplate = new CMultiDocTemplate(
IDR_MFCVIETYPE,
RUNTIME_CLASS(CMFCVIEWDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CMFCVIEWView));
AddDocTemplate(pDocTemplate); // create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) //在这里调用
return FALSE;
m_pMainWnd = pMainFrame;也就是说在程序的InitInstance()函数里进行调用,其功能是建立CMDIFrameWnd窗口。