CCreateContext context; context.m_pCurrentDoc=pDoc;// use existing document context.m_pCurrentFrame=NULL;//pFrame;// new child frame to be upon context.m_pNewViewClass=pViewClass;// RUNTIME_CLASS(CMyHtmlView);// new view to be created context.m_pNewDocTemplate=NULL;//pTemplate;// use existing document template context.m_pLastView=NULL;// no //TRACE0("Before LoadFrame()\n"); if (!pFrame->LoadFrame(nIDResource,WS_OVERLAPPEDWINDOW|FWS_ADDTOTITLE,AfxGetMainWnd()/*this*/,&context)) { TRACE0("Warning: Couldn't load frame window!\n"); AfxMessageBox("Warning: Couldn't load frame window!\n"); return -1; } //TRACE0("After LoadFrame()\n"); pFrame->InitialUpdateFrame(pDoc,TRUE); //just delagate to implementation in CFrameWnd //pTemplate->InitialUpdateFrame(pHtmlChild,pDoc,TRUE);
//it worked! return 0; }调用的时候可以这样void CMainFrame::OnMapView() { // TODO: Add your command handler code here CDocument* pDoc=MDIGetActive()->GetActiveDocument(); CreateNewView(IDI_ICON_MAP,RUNTIME_CLASS(CChildFrame4Map),RUNTIME_CLASS(CMapXView),pDoc); } 实现视图前还更加简单了,获取视图激活就行。
如果这样,你可以这样子。
int CMainFrame::CreateNewView(UINT nIDResource, CRuntimeClass *pFrameClass, CRuntimeClass *pViewClass, CDocument *pDoc)
{
CMDIChildWnd* pFrame=(CMDIChildWnd*)pFrameClass->CreateObject();
ASSERT_KINDOF(CMDIChildWnd, pFrame);
ASSERT_VALID(pDoc);
CDocTemplate* pTemplate=pDoc->GetDocTemplate();
//ASSERT_VALID(pTemplate);
CCreateContext context;
context.m_pCurrentDoc=pDoc;// use existing document
context.m_pCurrentFrame=NULL;//pFrame;// new child frame to be upon
context.m_pNewViewClass=pViewClass;// RUNTIME_CLASS(CMyHtmlView);// new view to be created
context.m_pNewDocTemplate=NULL;//pTemplate;// use existing document template
context.m_pLastView=NULL;// no
//TRACE0("Before LoadFrame()\n");
if (!pFrame->LoadFrame(nIDResource,WS_OVERLAPPEDWINDOW|FWS_ADDTOTITLE,AfxGetMainWnd()/*this*/,&context))
{
TRACE0("Warning: Couldn't load frame window!\n");
AfxMessageBox("Warning: Couldn't load frame window!\n");
return -1;
}
//TRACE0("After LoadFrame()\n");
pFrame->InitialUpdateFrame(pDoc,TRUE);
//just delagate to implementation in CFrameWnd
//pTemplate->InitialUpdateFrame(pHtmlChild,pDoc,TRUE);
//it worked!
return 0;
}调用的时候可以这样void CMainFrame::OnMapView()
{
// TODO: Add your command handler code here
CDocument* pDoc=MDIGetActive()->GetActiveDocument();
CreateNewView(IDI_ICON_MAP,RUNTIME_CLASS(CChildFrame4Map),RUNTIME_CLASS(CMapXView),pDoc);
}
实现视图前还更加简单了,获取视图激活就行。
或着是这样的也行 是个多文档程序 在CChildFrame窗口里 继续创建文档窗口 ,也就是说在文档窗口里还可以创建文档窗口