博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【VS开发】CTabView多页卡界面
阅读量:4589 次
发布时间:2019-06-09

本文共 2945 字,大约阅读时间需要 9 分钟。

目录

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

class CTabbedView : public CView
Members

Public Methods

Name

Description

Adds a new view to the tab control.

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

Returns a pointer to the currently active view

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

Removes the view from the tab control.

Makes a view active.

Protected Methods

Name

Description

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

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。

转载于:https://www.cnblogs.com/huty/p/8518683.html

你可能感兴趣的文章
基于用户的协同过滤(UserCF)
查看>>
运行Storm实例
查看>>
MapReduce各个执行阶段
查看>>
Shuffle过程详解
查看>>
微软云数据库SQL Azure
查看>>
Amazon DynamoDB
查看>>
云数据库概念
查看>>
云数据库与其他数据库的关系
查看>>
HBase 表和Region
查看>>
HBase功能组件
查看>>
UMP系统架构 RabbitMQ
查看>>
UMP系统架构 Mnesia
查看>>
UMP系统架构 Controller服务器
查看>>
UMP系统架构 Zookeeper
查看>>
HBase+Redis
查看>>
UMP系统架构 LVS
查看>>
Store工作原理
查看>>
HBase Ambari
查看>>
HLog工作原理
查看>>
构建HBase二级索引
查看>>