CTabView使用方法

来源:互联网 发布:品质淘生活 淘宝达人 编辑:程序博客网 时间:2024/05/17 08:46

可以利用ctabview实现多视图切换,新进的项目需要这个,网上搜了下,内容比价小,自己钻研了下弄出来了。

1.新建一个CTabView的继承类

重载相关函数

void CMyTabViewExt::OnInitialUpdate(){CTabView::OnInitialUpdate();// TODO: Add your specialized code here and/or call the base classthis -> GetTabControl().SetLocation( CMFCTabCtrl::LOCATION_BOTTOM/*LOCATION_TOP*/);    //方向向下this -> GetTabControl().ModifyTabStyle( CMFCTabCtrl:: STYLE_3D_ONENOTE);    //风格this -> GetTabControl().EnableAutoColor( TRUE );  //自动着色this -> GetTabControl().SetTabBorderSize(1); //边框大小this -> GetTabControl().HideSingleTab( TRUE );   //单个Tab时候不显示Tab标签this -> GetTabControl().EnableTabSwap( FALSE );    //禁止拖动//SetTimer(MANUAL_TABLE_TIME,1000,NULL);this -> GetTabControl().EnableActiveTabCloseButton(TRUE);this->GetTabControl().ShowTab(1,FALSE,TRUE);this->GetTabControl().ShowTab(2,FALSE,TRUE);}int CMyTabViewExt::OnCreate(LPCREATESTRUCT lpCreateStruct){if (CTabView::OnCreate(lpCreateStruct) == -1)return -1;// TODO:  Add your specialized creation code hereCString strText;strText = _T("First TabView");AddView(RUNTIME_CLASS(CMyTopView),strText,1);strText = _T("Second TabView");AddView(RUNTIME_CLASS(CMyModifyView),strText,2);return 0;}void CMyTabViewExt::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint){// TODO: Add your specialized code here and/or call the base classCCMyTabViewTestDoc* pDoc = dynamic_cast<CCMyTabViewTestDoc*>(m_pDocument);//CCMyTabViewTestDoc* pDoc = (CCMyTabViewTestDoc *)m_pDocument;if (NULL == pDoc){ASSERT(pDoc);return;}switch(lHint){case TOP_VIEW:// m_ViewID = TOP_VIEW;// CView* pView = this->GetActiveView();if (this->GetTabControl().IsTabVisible(0)&&!this->GetTabControl().IsTabVisible(0)){return;}//this->GetTabControl().ShowTab(2,FALSE,FALSE,FALSE);this->GetTabControl().ShowTab(0,TRUE,TRUE,TRUE);this->GetTabControl().SetActiveTab(0);this->GetDocument()->UpdateAllViews(NULL,BOTTOM_VIEW_HIDE,NULL);break;case BOTTOM_VIEW:if (!this->GetTabControl().IsTabVisible(0)&&this->GetTabControl().IsTabVisible(1)){return;}//this->GetTabControl().ShowTab(1,FALSE,FALSE);this->GetTabControl().ShowTab(1,TRUE,TRUE,TRUE);//this->GetTabControl().SetActiveTab(1);this->GetDocument()->UpdateAllViews(NULL,TOP_VIEW_HIDE,NULL);break;case ALL_VIEW:if (this->GetTabControl().IsTabVisible(0) && this->GetTabControl().IsTabVisible(1)){return;}this->GetTabControl().ShowTab(0,TRUE,TRUE);this->GetTabControl().ShowTab(1,TRUE,TRUE);this->SetActiveView(0);break;case TOP_VIEW_HIDE:this->GetTabControl().ShowTab(0,FALSE,TRUE);break;case BOTTOM_VIEW_HIDE:this->GetTabControl().ShowTab(1,FALSE,TRUE);break;default:if (this->GetTabControl().IsTabVisible(0) || this->GetTabControl().IsTabVisible(1)){return;}this->GetTabControl().ShowTab(0,TRUE,TRUE,TRUE);this->GetTabControl().ShowTab(1,FALSE,TRUE);this->GetTabControl().SetActiveTab(0);}}


2.


pDocTemplate = new CMultiDocTemplate(/*IDR_CMyTabViewTestTYPE*/IDR_MAINFRAME,RUNTIME_CLASS(CCMyTabViewTestDoc),RUNTIME_CLASS(CChildFrame), // custom MDI child frameRUNTIME_CLASS(CCMyTabViewTestView/*CMyTabViewExt*/));//CCMyTabViewTestView继承至CMyTabViewEX


3.视图切换

void CMainFrame::OnTabshowTopview(){// TODO: Add your command handler code hereCMDIChildWnd* pMDIAcitve = MDIGetActive();if (pMDIAcitve){CCMyTabViewTestDoc* pDoc = (CCMyTabViewTestDoc*)(pMDIAcitve->GetActiveDocument());if (pDoc == NULL){ASSERT(pDoc);}pDoc->UpdateAllViews(NULL,TOP_VIEW,NULL);}}void CMainFrame::OnTabshowBottomview(){// TODO: Add your command handler code hereCMDIChildWnd* pMDIAcitve = MDIGetActive();if (pMDIAcitve){CCMyTabViewTestDoc* pDoc = (CCMyTabViewTestDoc*)(pMDIAcitve->GetActiveDocument());if (pDoc == NULL){ASSERT(pDoc);}pDoc->UpdateAllViews(NULL,BOTTOM_VIEW,NULL);}}void CMainFrame::OnTabshowAllshow(){// TODO: Add your command handler code hereCMDIChildWnd* pMDIAcitve = MDIGetActive();if (pMDIAcitve){CCMyTabViewTestDoc* pDoc = (CCMyTabViewTestDoc*)(pMDIAcitve->GetActiveDocument());if (pDoc == NULL){ASSERT(pDoc);}pDoc->UpdateAllViews(NULL,ALL_VIEW,NULL);}}

4.重载视图的WM_CLOSE函数

void CMyTopView::OnClose(){// TODO: Add your message handler code here and/or call defaultthis->GetDocument()->UpdateAllViews(NULL,TOP_VIEW_HIDE,NULL);CFormView::OnClose();}




0 0
原创粉丝点击