切换视图: void CMainFrame::SwitchView(UINT nViewID) { CView *pOldActiveView =GetActiveView(); CView *pNewActiveView=(CView*)GetDlgItem(nViewID); if(pNewActiveView==NULL) { switch(nViewID) { case IDD_RECORD_VIEW: pNewActiveView=new CResultView(); break; case IDD_USELISTVIEW_FORM: pNewActiveView=new CUseListViewView(); break; case ID_MAIN_VIEW: pNewActiveView=new CWordRecordView(); break; }
CCreateContext context; context.m_pCurrentDoc=pOldActiveView->GetDocument(); //add the flag:WS_BORDER,or the view will capture all the client included the windowrect! pNewActiveView->Create(NULL,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,CFrameWnd::rectDefault,this,nViewID,&context); pNewActiveView->OnInitialUpdate(); } SetActiveView(pNewActiveView); pNewActiveView->ShowWindow(SW_SHOW); pOldActiveView->ShowWindow(SW_HIDE); //I use the win32 based function:SetWindowLong() instead of the older style:SetWindowWord() ::SetWindowLong(pNewActiveView->m_hWnd,GWL_ID,AFX_IDW_PANE_FIRST); this->RecalcLayout(); delete pOldActiveView; }void CMainFrame::OnFormview() { // TODO: Add your command handler code here this->SwitchView(ID_MAIN_VIEW); }void CMainFrame::OnMainview() { // TODO: Add your command handler code here this->SwitchView(IDD_USELISTVIEW_FORM); }void CMainFrame::OnResultview() { // TODO: Add your command handler code here this->SwitchView(IDD_RECORD_VIEW); } ——————————————————————————————
void CMainFrame::SwitchView(UINT nViewID)
{
CView *pOldActiveView =GetActiveView();
CView *pNewActiveView=(CView*)GetDlgItem(nViewID);
if(pNewActiveView==NULL)
{
switch(nViewID)
{
case IDD_RECORD_VIEW:
pNewActiveView=new CResultView();
break;
case IDD_USELISTVIEW_FORM:
pNewActiveView=new CUseListViewView();
break;
case ID_MAIN_VIEW:
pNewActiveView=new CWordRecordView();
break;
}
CCreateContext context;
context.m_pCurrentDoc=pOldActiveView->GetDocument();
//add the flag:WS_BORDER,or the view will capture all the client included the windowrect!
pNewActiveView->Create(NULL,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,CFrameWnd::rectDefault,this,nViewID,&context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
//I use the win32 based function:SetWindowLong() instead of the older style:SetWindowWord()
::SetWindowLong(pNewActiveView->m_hWnd,GWL_ID,AFX_IDW_PANE_FIRST);
this->RecalcLayout();
delete pOldActiveView;
}void CMainFrame::OnFormview()
{
// TODO: Add your command handler code here
this->SwitchView(ID_MAIN_VIEW);
}void CMainFrame::OnMainview()
{
// TODO: Add your command handler code here
this->SwitchView(IDD_USELISTVIEW_FORM);
}void CMainFrame::OnResultview()
{
// TODO: Add your command handler code here
this->SwitchView(IDD_RECORD_VIEW);
}
——————————————————————————————