在CMainFrame下定义SwitchToView函数,如下:void CMainFrame::SwitchToView(CDocTemplate *pTemplate, CRuntimeClass * pViewClass) { CMDIChildWnd *pMDIActive=MDIGetActive();//get the active CMDIChildWnd CDocument* pDoc; if(pMDIActive==NULL)//if there is no active ChildFrame { pTemplate->OpenDocumentFile(NULL); return; } else pDoc=pMDIActive->GetActiveDocument();
CView *pView; POSITION pos=pDoc->GetFirstViewPosition(); while(pos!=NULL) { pView=pDoc->GetNextView(pos); if(pView->IsKindOf(pViewClass))//find the active frame //if has ,get the activedocument //have the view ; { pView->GetParentFrame()->ActivateFrame(); return; } } CMDIChildWnd *pNewFrame=(CMDIChildWnd*) pTemplate->CreateNewFrame(pDoc,NULL); if(pNewFrame==NULL) return; pTemplate->InitialUpdateFrame(pNewFrame,pDoc);} 再在相应的菜单函数中加入 SwitchToView(theApp.pChart,RUNTIME_CLASS(CChart)); 其中pChart为相应的多文档模板指针,CChart为定义的视图类
TO: gemi(翔) 我用你的代码试了一下,不过感觉你的是单文档的,我有多有文档模板,要在它们之间创建或切换. 我改了一下,把它改成适合多文档的情形,但我有一个视图是从CEditView继承来的,用了那个函数后,用视图类调用GetEditCtrl(),得不到Edit控件啊??????????????????????????????
http://www.czvc.com/down.asp?id=10
pViewClass)
{
CMDIChildWnd *pMDIActive=MDIGetActive();//get the active CMDIChildWnd
CDocument* pDoc;
if(pMDIActive==NULL)//if there is no active ChildFrame
{
pTemplate->OpenDocumentFile(NULL);
return;
}
else
pDoc=pMDIActive->GetActiveDocument();
CView *pView;
POSITION pos=pDoc->GetFirstViewPosition();
while(pos!=NULL)
{
pView=pDoc->GetNextView(pos);
if(pView->IsKindOf(pViewClass))//find the active frame
//if has ,get the activedocument
//have the view ;
{
pView->GetParentFrame()->ActivateFrame();
return;
}
}
CMDIChildWnd *pNewFrame=(CMDIChildWnd*)
pTemplate->CreateNewFrame(pDoc,NULL);
if(pNewFrame==NULL)
return;
pTemplate->InitialUpdateFrame(pNewFrame,pDoc);}
再在相应的菜单函数中加入
SwitchToView(theApp.pChart,RUNTIME_CLASS(CChart));
其中pChart为相应的多文档模板指针,CChart为定义的视图类
CView *pView = (CView*)(m_pParent->FromHandle((HWND)pResult->DocInfo.hViewWnd));
if (NULL == pView)
{
return FALSE;
}
CMDIChildWnd *pChild = (CMDIChildWnd*)pView->GetParent();
if (NULL == pChild)
{
return FALSE;
}
pChild->MDIActivate();
激活指定的doc打开是标准的,只要响应
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
就可以打开或者是新建了,不知道你具体的问题是什么?
CxxxView *pView;
POSITION pos = GetDocument()->GetFirstViewPosition();
pView = (CxxxView *)GetDocument()->GetNextView(pos);
while(!pView->IsKindOf(RUNTIME_CLASS(CxxxView)))
{
pView = (CxxxView *)GetDocument()->GetNextView(pos);
} 你就能得到view的指针了创建的,根据名字就行了把
我用你的代码试了一下,不过感觉你的是单文档的,我有多有文档模板,要在它们之间创建或切换.
我改了一下,把它改成适合多文档的情形,但我有一个视图是从CEditView继承来的,用了那个函数后,用视图类调用GetEditCtrl(),得不到Edit控件啊??????????????????????????????
改过来后就好了.
谢谢各位!