Click here to Skip to main content
11,485,334 members (80,777 online)
Click here to Skip to main content

CXTabCtrl: an easier tab control for dialogs and forms

, 26 Jun 2000 315.7K 6.8K 74
Rate this:
Please Sign up or sign in to vote.
An easier tab control
<!-- Link to demo file download --> <!-- Article image -->

Sample Image - CXTabControl.gif

<!-- Add the rest of your HTML here -->


When I first started using Microsoft VC++, I found it boring to put a tab control in a form or in a dialog. I had to create the dialogs, fill in the TCITEM structure for each of my tabs, and finally insert them into the tab control. With CXTabCtrl it is far simpler, as is illustrated below:-

InitDialog (CDialog) or InitialUpdate (CFormView) 

m_pMyDlg = new CMyDlg;
m_pMyDlg->Create(CMyDlg::IDD, &m_tabctrl /*CXTabCtrl variable*/);
m_tabctrl.AddTab(m_pMyDlg, "Tab caption", 0 /* image number*/);

The OnSelChange that you previously had to implement in the dialog (or form) to show the correct dialog is now in the CXTabCtrl, so you don't have to worry about it. You can even disable a tab so the user cannot see its contents.

m_tabctrl.EnableTab(1 /*index*/, FALSE);

You can also change the color for the following states of each tab:-

  • Selected tab
  • Unselected tab
  • Disabled tab
  • A mouse over tab
  • You can select a tab from it's caption, or dynamically change a tab. In addition to this, you can select the previous or next tab with the SelectNextTab method.


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Architect VisionOne AG
    Switzerland Switzerland
    XicoLoko is a brazilian developer based in Switzerland.

    Comments and Discussions

    QuestionMFC Tab Control Video Tutorials Pin
    Jack123sweet5-Apr-14 9:20
    memberJack123sweet5-Apr-14 9:20 
    AnswerRe: MFC Tab Control Video Tutorials Pin
    Vaughan Daniel13-May-14 11:02
    memberVaughan Daniel13-May-14 11:02 
    GeneralGetItem() failed! [modified] Pin
    Harly11-Jul-12 16:30
    memberHarly11-Jul-12 16:30 
    GeneralMy vote of 3 Pin
    fishpixie19-Mar-11 21:14
    memberfishpixie19-Mar-11 21:14 
    GeneralProposition Pin
    voy k16-May-06 21:11
    membervoy k16-May-06 21:11 
    void CXTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)


    if( IsTabEnabled( nTabIndex ) )
    pImageList->Draw( pDC, item.iImage, CPoint( rect.left, nYpos ), ILD_TRANSPARENT );
    HICON hIconImage = pImageList->ExtractIcon( item.iImage );

    pDC->DrawState( CPoint( rect.left, nYpos ), CSize( 16, 16 ), (HICON)hIconImage, DSS_DISABLED, (CBrush *)NULL );

    DestroyIcon( hIconImage );


    BOOL CXTabCtrl::SelectNextTab( BOOL bForward )
    int iSum = bForward ? 1 : -1;
    int iCurSel = GetCurSel();
    ASSERT( iCurSel > -1 && iCurSel < GetItemCount() );

    int iCurSelSave( iCurSel );

    iCurSel += iSum;

    if( iCurSel < 0 )
    iCurSel = GetItemCount() - 1;
    else if( iCurSel >= GetItemCount() )
    iCurSel = 0;

    if( IsTabEnabled( iCurSel ) )
    SelectTab( iCurSel );

    return TRUE;

    while( iCurSel != iCurSelSave );

    return FALSE;

    GeneralAccess the edit control inside the tab Pin
    iulikii_026-Apr-06 3:46
    memberiulikii_026-Apr-06 3:46 
    Questionhow can i ................ Pin
    alupiv29-Mar-06 19:35
    memberalupiv29-Mar-06 19:35 
    QuestionHow to know which page is selected Pin
    cyberaoul5-Oct-05 23:47
    membercyberaoul5-Oct-05 23:47 
    QuestionHelp,how can i change it's size? Pin
    Lancelot Yuan10-Jul-05 16:33
    memberLancelot Yuan10-Jul-05 16:33 
    AnswerRe: Help,how can i change it's size? [modified] Pin
    pajero_pn11-Jan-08 22:40
    memberpajero_pn11-Jan-08 22:40 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.150520.1 | Last Updated 27 Jun 2000
    Article Copyright 2000 by xicoloko
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid