Click here to Skip to main content
Click here to Skip to main content

CXTabCtrl: an easier tab control for dialogs and forms

, 26 Jun 2000
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

    GeneralDoesn't look good on WinXP PinsussMirzallica6-Jul-03 15:09 
    GeneralDrag and Drop in a tab Control dialog PinmemberYohome10-Jun-03 3:30 
    Generalonsize problem... Pinmemberopcode11272-Jun-03 22:00 
    GeneralBug: Inhibit Hot key Pinmemberericlts7-May-03 20:50 
    GeneralPlease Help me!! PinmemberAnsonku1-May-03 5:04 
    GeneralRe: Please Help me!! Pinmembertainy3-May-03 14:34 
    GeneralRe: Please Help me!! PinmemberPeter B.22-May-03 11:38 
    GeneralRe: Please Help me!! Pinmembercjpm10025-Jul-04 5:08 
    tabtestdlg.h(23) : error C2146: syntax error : missing ';' before identifier 'm_MyTab'
    tabtestdlg.h(23) : error C2501: 'CXTabCtrl' : missing storage-class or type specifiers
    tabtestdlg.h(23) : error C2501: 'm_MyTab' : missing storage-class or type specifiers
    TabTestDlg.cpp(77) : error C2065: 'm_MyTab' : undeclared identifier
    Generating Code...
    Error executing cl.exe.
    TabTest.exe - 7 error(s), 0 warning(s)
    Can someone explain why this doesnt work for me? I used ClassWizard to assign a standard CTabCtrl variable to the Tab Control, and then modified the line to read CXTabCtrl as below:
    enum { IDD = IDD_TABTEST_DIALOG };
    CXTabCtrl m_MyTab;
    I havent been able to get this procedure to work in other CodeProject things, so I assume its my doing!!
    Please help, much appreciated.

    GeneralRe: Please Help me!! Pinmemberrthat14-Feb-05 3:40 
    GeneralRe: Please Help me!! Pinmemberrthat14-Feb-05 6:32 
    Generalhwo can iset icon to the tab Pinmemberliquidsnake18329-Mar-03 12:47 
    GeneralModifying Text on Tab Pinsussmistroseth26-Mar-03 3:20 
    GeneralFormView PinmemberDscho6-Feb-03 23:23 
    GeneralFormView Sample Pinmemberbpwallac25-Jan-03 19:20 
    GeneralCTabCtrlSSL is better Pinmembernomadik13-Jan-03 0:36 
    GeneralRe: CTabCtrlSSL is better Pinmemberericlts7-May-03 20:25 
    GeneralRe: CTabCtrlSSL is better Pinmemberdchris_med24-Apr-08 15:13 
    GeneralExcellent job!!! Pinmemberkevindu9-Jan-03 15:00 
    QuestionKeyboard navigation? PinsussAnonymous1-Nov-02 23:06 
    Generaldynamic delete tabs Pinmembersilverspoon24-Jul-02 23:01 
    GeneralRe: dynamic delete tabs PinsussAnonymous2-Aug-02 1:54 
    QuestionHow to set the caption dynamically ? PinmemberKumar119-Feb-02 18:40 
    AnswerRe: How to set the caption dynamically ? Pinmemberminuo22-Mar-02 10:38 
    GeneralRe: How to set the caption dynamically ? PinsussAnonymous19-Sep-02 9:02 
    Generalno tabs PinmemberAMW9-Nov-01 20:31 

    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.141223.1 | Last Updated 27 Jun 2000
    Article Copyright 2000 by xicoloko
    Everything else Copyright © CodeProject, 1999-2014
    Layout: fixed | fluid