1个回答
2013-08-16
展开全部
是不是单文档多视程序进行视图切换的代码函数
void CMainFrame::SwitchToForm(int nForm) //进行视图切换的代码函数
{
//CDocument* pDoc = GetActiveDocument();
CView *pOldActiveView=GetActiveView(); //保存旧视图
CView *pNewActiveView=(CView*)GetDlgItem(nForm); //取得新视图
if(pNewActiveView==NULL)
{
switch(nForm)
//这些ID是对话框的标志符,但也可以用其他的标志
{
case IDD_MULTIVIEW_FORM :
pNewActiveView=(CView*)new CView1;
break;
case IDD_MULTIVIEW_FORM2 :
pNewActiveView=(CView*)new CView2;
break;
case IDD_MULTIVIEW_FORM3 :
pNewActiveView=(CView*)new CView3;
break;
case IDD_MULTIVIEW_FORM4 :
pNewActiveView=(CView*)new CView4;
break;
}
CCreateContext context; //将文挡和视图相连
context.m_pCurrentDoc=pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, WS_BORDER|WS_CHILD ,
CFrameWnd::rectDefault, this, nForm, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView); //改变活动的视图
pNewActiveView->ShowWindow(SW_SHOW); //显示新的视图
pOldActiveView->ShowWindow(SW_HIDE); //隐藏旧的视图
if(pOldActiveView->GetRuntimeClass() ==RUNTIME_CLASS(CView1))
pOldActiveView->SetDlgCtrlID(IDD_MULTIVIEW_FORM);
else if(pOldActiveView->GetRuntimeClass() ==RUNTIME_CLASS(CView2))
pOldActiveView->SetDlgCtrlID(IDD_MULTIVIEW_FORM2);
else if(pOldActiveView->GetRuntimeClass() ==RUNTIME_CLASS(CView3))
pOldActiveView->SetDlgCtrlID(IDD_MULTIVIEW_FORM3);
else if(pOldActiveView->GetRuntimeClass() ==RUNTIME_CLASS(CView4))
pOldActiveView->SetDlgCtrlID(IDD_MULTIVIEW_FORM4);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
delete pOldActiveView; //删除旧视图
RecalcLayout(); //调整框架窗口
}
你可以参考下
void CMainFrame::SwitchToForm(int nForm) //进行视图切换的代码函数
{
//CDocument* pDoc = GetActiveDocument();
CView *pOldActiveView=GetActiveView(); //保存旧视图
CView *pNewActiveView=(CView*)GetDlgItem(nForm); //取得新视图
if(pNewActiveView==NULL)
{
switch(nForm)
//这些ID是对话框的标志符,但也可以用其他的标志
{
case IDD_MULTIVIEW_FORM :
pNewActiveView=(CView*)new CView1;
break;
case IDD_MULTIVIEW_FORM2 :
pNewActiveView=(CView*)new CView2;
break;
case IDD_MULTIVIEW_FORM3 :
pNewActiveView=(CView*)new CView3;
break;
case IDD_MULTIVIEW_FORM4 :
pNewActiveView=(CView*)new CView4;
break;
}
CCreateContext context; //将文挡和视图相连
context.m_pCurrentDoc=pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, WS_BORDER|WS_CHILD ,
CFrameWnd::rectDefault, this, nForm, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView); //改变活动的视图
pNewActiveView->ShowWindow(SW_SHOW); //显示新的视图
pOldActiveView->ShowWindow(SW_HIDE); //隐藏旧的视图
if(pOldActiveView->GetRuntimeClass() ==RUNTIME_CLASS(CView1))
pOldActiveView->SetDlgCtrlID(IDD_MULTIVIEW_FORM);
else if(pOldActiveView->GetRuntimeClass() ==RUNTIME_CLASS(CView2))
pOldActiveView->SetDlgCtrlID(IDD_MULTIVIEW_FORM2);
else if(pOldActiveView->GetRuntimeClass() ==RUNTIME_CLASS(CView3))
pOldActiveView->SetDlgCtrlID(IDD_MULTIVIEW_FORM3);
else if(pOldActiveView->GetRuntimeClass() ==RUNTIME_CLASS(CView4))
pOldActiveView->SetDlgCtrlID(IDD_MULTIVIEW_FORM4);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
delete pOldActiveView; //删除旧视图
RecalcLayout(); //调整框架窗口
}
你可以参考下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询