zoukankan      html  css  js  c++  java
  • 【VS开发】CTabView多页卡界面

    The CTabView class simplifies the use of the tab control class (CMFCTabCtrl ) in applications that use MFC's document/view architecture.

    class CTabbedView : public CView
    Members

    Public Methods

    Name

    Description

    CTabView::AddView

    Adds a new view to the tab control.

    CTabView::FindTab

    Returns the index of the specified view in the tab control.

    CTabView::GetActiveView

    Returns a pointer to the currently active view

    CTabView::GetTabControl

    Returns a reference to the tab control associated with the view.

    CTabView::RemoveView

    Removes the view from the tab control.

    CTabView::SetActiveView

    Makes a view active.

    Protected Methods

    Name

    Description

    CTabView::IsScrollBar

    Called by the framework when creating a tab view to determine whether the tab view has a shared horizontal scroll bar.

    CTabView::OnActivateView

    Called by the framework when the tab view is made active or inactive.

     


    使用CTabView要特别注意获取视图的指针的操作,一般的途径获取只能获取CTabView里面的当前View不能获取到CTabView指针,必须通过下面方法获取,以下为在主框架获取CTabView视图指针的示例:

     

    void  CMainFrame:: OnGetBlog() 
    {   
        CChildFrame * pChildFrm =  ( CChildFrame *) GetActiveFrame();  
        CView *  pView =  pChildFrm-> GetActiveView(); 
        CMFCTabCtrl *  pParent1 =  ( CMFCTabCtrl *) pView-> GetParent(); 
        CXXXTabView *  pTabView =( CXXXTabView *)  pParent1-> GetParent();  
        pTabView-> OnBlog();    //调用CTabView视图类里面的函数
    }

     


     

    要禁止CTabView里面的Tab拖动,只需要在CTabView里面调用下面:

    this -> GetTabControl().EnableTabSwap( FALSE );

     


     

    一些CTabView样式设置,如下:

    void  CXXXTabView:: OnInitialUpdate() 
    { 
        CTabView:: OnInitialUpdate(); 
        AddView ( RUNTIME_CLASS ( CView1),  _T( " simple " ),  100 ); 

        this -> GetTabControl().SetLocation( CMFCTabCtrl:: LOCATION_TOP);    //方向上顶
        this -> GetTabControl().ModifyTabStyle( CMFCTabCtrl:: STYLE_3D_ONENOTE);    //风格
        this -> GetTabControl().EnableAutoColor( TRUE );  //自动着色
        this -> GetTabControl().SetTabBorderSize( 2 ); //边框大小
        this -> GetTabControl().HideSingleTab( TRUE );   //单个Tab时候不显示Tab标签
        this -> GetTabControl().EnableTabSwap( FALSE );    //禁止拖动
    }

     


     

    若是要禁止CTabView上的滚动条,只要在CTabView的头文件上,定义以下函数即可:

    BOOL  IsScrollBar ()  const 
    { 
        return  FALSE ; 
    }

     

    在基于CTabView的多文档中,遍历每个CTabView视图可以通过获取框架指针。下面是关闭除当前视图外的其余视图:

    void CMainFrame::OnFileAllClose()
    {
        CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
        CMDIChildWnd *pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();   
        CView * pView;
        CMFCTabCtrl * pParent1;
        CXXXTabView * pTabView;
        CDocument* pDoc;

        CMDIChildWnd *pChild2=pFrame->MDIGetActive();
        if (pFrame)
        {
            //依次关闭右边视图
            pFrame->MDINext();
            pChild2=pFrame->MDIGetActive();
            while (pChild2!=pChild)
            {           
                pView = pChild2->GetActiveView();
                pParent1 = (CMFCTabCtrl *)pView->GetParent();
                pTabView =(CXXXTabView *) pParent1->GetParent();
                pDoc = pTabView->GetDocument();    
                pDoc->OnCloseDocument();         
                pChild2=pFrame->MDIGetActive();
            }
            //依次关闭左边视图
            pFrame->MDIPrev();
            pChild2=pFrame->MDIGetActive();
            while (pChild2!=pChild)
            {
                pView = pChild2->GetActiveView();
                pParent1 = (CMFCTabCtrl *)pView->GetParent();
                pTabView =(CXXXTabView *) pParent1->GetParent();
                pDoc = pTabView->GetDocument();    
                pDoc->OnCloseDocument();
                pFrame->MDIPrev();
                pChild2=pFrame->MDIGetActive();
            }
        }    
    }

    更多的资料,可以参考MSDN。

  • 相关阅读:
    [quote]HowTo Format Date For Display or Use In a Shell Script
    [quote] standard Input and Output Redirection
    [quote] Re: [ECOS] printf and diag_printf go to nowhere 2
    [quote] Re: [ECOS] printf and diag_printf go to nowhere
    [quote] DMA engine in Linux Kernel
    [linux]How to set PATH in shell script, and keep it avaiable even after it exits
    use AWK to extract some lines according to some patterns in file
    [Reprinted] Howto Use Linux Watchdog
    Hadoop 1 ecosystem
    Java Comparable & Comparator
  • 原文地址:https://www.cnblogs.com/huty/p/8518683.html
Copyright © 2011-2022 走看看