获取CTabView的指针以及禁止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。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值