1.为每个视图定义ID
2.定义个SwitchView(nvID)的函数
CView *pOld=GetActiveView();
CView *pNew=(CView*)GetDlgItem(nvID);
if(pNew==NULL)//如果第一次的话
{
switch(nV)
{
case IDVIEW_XXX:
pNew=(CView*) new CMyViewXXX;
break;
case IDVIEW_XXX:
pNew=(CView*) new CMyViewXXX;
break;
}
CCreateContext context;
context.m_pCurrentDoc=pOld->GetDocument();
pNew->Create(NULL,NULL,WS_BORDER,
CFrameWnd::rectDefault,this,nvID,&context);
pNew->OnInitialUpdate();
}
this->SetActiveView(pNew);
pNew->ShowWindow(SW_SHOW);
pOld->ShowWindow(SW_HIDE);
pOld->SetDlgCtrlID(
pOld->GetRuntimeClass()==RUNTIME_CLASS(CMyEdit)?0:1);
//此处必须旧的视图的ID改回你设置的ID,因为当它活动的时候
//ID是AFX_IDW_PANE_FIRST
pNew->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
//当前活动视图ID必须是AFX_IDW_PANE_FIRST
this->RecalcLayout();
4.菜单设置
pCmdUI->Enable(!GetActiveView()->IsKindOf(RUNTIME_CLASS(CMyView)));