Click here to Skip to main content
15,889,767 members
Articles / Desktop Programming / MFC
Article

CXTabCtrl: an easier tab control for dialogs and forms

Rate me:
Please Sign up or sign in to vote.
4.50/5 (32 votes)
26 Jun 2000 377.1K   7.8K   77   79
An easier tab control

Sample Image - CXTabControl.gif

Introduction

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.

    License

    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


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

    Comments and Discussions

     
    QuestionKeyboard navigation? Pin
    Anonymous1-Nov-02 22:06
    Anonymous1-Nov-02 22:06 
    Generaldynamic delete tabs Pin
    silverspoon24-Jul-02 22:01
    silverspoon24-Jul-02 22:01 
    GeneralRe: dynamic delete tabs Pin
    Anonymous2-Aug-02 0:54
    Anonymous2-Aug-02 0:54 
    QuestionHow to set the caption dynamically ? Pin
    19-Feb-02 17:40
    suss19-Feb-02 17:40 
    AnswerRe: How to set the caption dynamically ? Pin
    22-Mar-02 9:38
    suss22-Mar-02 9:38 
    GeneralRe: How to set the caption dynamically ? Pin
    littledragon2319-Sep-02 8:02
    littledragon2319-Sep-02 8:02 
    Generalno tabs Pin
    9-Nov-01 19:31
    suss9-Nov-01 19:31 
    GeneralMore instructions please Pin
    21-Sep-01 4:17
    suss21-Sep-01 4:17 
    I really appreciate people who post examples like this because it helps
    me immensely but the thing that really bugs me is that I see something that
    looks really simple to implement ( like this one ) and when I go to compile
    my project, I get an on-going number of "Not found" messages because I didn't
    include everything that needs to be included.

    For example. I need to include XTabCtrl obviously.
    But When I compiled with that it needs CTabCtrl (this isn't even explained anywhere).
    Then When I include that, I get an error saying it needs the header file to the Dialog class.
    I'm still debugging this after an hour and a half.

    Again, I appreciate the program example but please give us a few more clues on the set-up.

    Thanks

    alan
    Dead | X|
    GeneralRe: More instructions please Pin
    Lindenbluete25-Jul-02 22:47
    Lindenbluete25-Jul-02 22:47 
    QuestionHow can I do to transfert datas ? Pin
    youssef24-Aug-01 0:08
    youssef24-Aug-01 0:08 
    AnswerRe: How can I do to transfert datas ? Pin
    chlud22-Apr-03 6:17
    chlud22-Apr-03 6:17 
    GeneralRe: How can I do to transfert datas ? Pin
    youssef22-Apr-03 6:33
    youssef22-Apr-03 6:33 
    GeneralRe: How can I do to transfert datas ? Pin
    chlud23-Apr-03 2:11
    chlud23-Apr-03 2:11 
    GeneralRe: How can I do to transfert datas ? Pin
    Yohome9-Jun-03 7:21
    Yohome9-Jun-03 7:21 
    GeneralRe: How can I do to transfert datas ? Pin
    youssef9-Jun-03 7:23
    youssef9-Jun-03 7:23 
    GeneralRe: How can I do to transfert datas ? Pin
    Yohome9-Jun-03 7:32
    Yohome9-Jun-03 7:32 
    AnswerRe: How can I do to transfert datas ? Pin
    fabioo6-May-03 5:33
    fabioo6-May-03 5:33 
    GeneralRe: How can I do to transfert datas ? Pin
    chrishide21-May-03 6:16
    chrishide21-May-03 6:16 
    QuestionCan I get the sample project with FORMVIEW (not dialog based)? Pin
    26-May-01 22:23
    suss26-May-01 22:23 
    AnswerRe: Can I get the sample project with FORMVIEW (not dialog based)? Pin
    23-Jun-01 0:53
    suss23-Jun-01 0:53 
    GeneralRe: Can I get the sample project with FORMVIEW (not dialog based)? Pin
    24-Jul-01 12:01
    suss24-Jul-01 12:01 
    GeneralRe: Can I get the sample project with FORMVIEW (not dialog based)? Pin
    24-Aug-01 3:15
    suss24-Aug-01 3:15 
    GeneralRe: Can I get the sample project with FORMVIEW (not dialog based)? Pin
    7-Nov-01 15:02
    suss7-Nov-01 15:02 
    GeneralSpawn a new window Pin
    27-Apr-01 11:38
    suss27-Apr-01 11:38 
    GeneralRe: Spawn a new window Pin
    20-Aug-01 2:30
    suss20-Aug-01 2:30 

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

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