怎样在MDI程序里面切换不同的 视图?

来源:互联网 发布:苹果播放器哪个好 知乎 编辑:程序博客网 时间:2024/05/01 05:11
 
我在MDI里面建立了两个视图和两个文档,怎样从一个 视图切换到另外一个视图?
        CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CVideoConferenceDoc),
RUNTIME_CLASS(CVideoConferenceChildFrame), // custom MDI child frame
RUNTIME_CLASS(CVideoConferenceView1));
AfxGetApp()->AddDocTemplate(pDocTemplate);
pDocument1=pDocTemplate->OpenDocumentFile(NULL);


pDocTemplate = new CMultiDocTemplate(
IDR_VIEW,
RUNTIME_CLASS(CVideoConferenceDoc),
RUNTIME_CLASS(CVideoConferenceChildFrame), // custom MDI child frame
RUNTIME_CLASS(CVideoConferenceView2));
AfxGetApp()->AddDocTemplate(pDocTemplate);
pDocument2=pDocTemplate->OpenDocumentFile(NULL);
void CMainFrame::SwitchToForm(CRuntimeClass *pRTClass)
{
    m_wndSplitter_2.DeleteView(1,0);//删除旧的视图
CCreateContext Context;
    Context.m_pNewViewClass=pRTClass;//创建新视
Context.m_pCurrentDoc=GetActiveDocument();//与当前活动文档相连
m_wndSplitter_2.CreateView(1,0,pRTClass,CSize(0,0),&Context);
//更新视图
CView *pView=(CView*)m_wndSplitter_2.GetPane(1,0);//获取分割视图
pView->ShowWindow(SW_SHOW);

pView->OnInitialUpdate();
SetActiveView(pView);
m_wndSplitter_2.RecalcLayout();
}
通过pDocTemplate用函数GetFirstDocPosition和GetNextDoc找到你的CDocument指针pDoc
然后通过pDoc用函数GetFirstViewPosition和GetNextView找到你的视类指针pView,
CMDIChildWnd * pFrm=(CMDIChildWnd *) pView->GetParentFrame();
if(pFrm)
{
  pFrm->MDIActivate(); //激活它就行了
}
原创粉丝点击