Click here to Skip to main content
11,416,787 members (68,366 online)
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 -->

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

    Share

    About the Author

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

    Comments and Discussions

     
    GeneralRe: Please Help me!! Pin
    Peter B.22-May-03 11:38
    memberPeter B.22-May-03 11:38 
    GeneralRe: Please Help me!! Pin
    cjpm10025-Jul-04 5:08
    membercjpm10025-Jul-04 5:08 
    GeneralRe: Please Help me!! Pin
    rthat14-Feb-05 3:40
    memberrthat14-Feb-05 3:40 
    GeneralRe: Please Help me!! Pin
    rthat14-Feb-05 6:32
    memberrthat14-Feb-05 6:32 
    Generalhwo can iset icon to the tab Pin
    liquidsnake18329-Mar-03 12:47
    memberliquidsnake18329-Mar-03 12:47 
    GeneralModifying Text on Tab Pin
    mistroseth26-Mar-03 3:20
    sussmistroseth26-Mar-03 3:20 
    GeneralFormView Pin
    Dscho6-Feb-03 23:23
    memberDscho6-Feb-03 23:23 
    GeneralFormView Sample Pin
    bpwallac25-Jan-03 19:20
    memberbpwallac25-Jan-03 19:20 
    GeneralCTabCtrlSSL is better Pin
    nomadik13-Jan-03 0:36
    membernomadik13-Jan-03 0:36 
    GeneralRe: CTabCtrlSSL is better Pin
    ericlts7-May-03 20:25
    memberericlts7-May-03 20:25 
    GeneralRe: CTabCtrlSSL is better Pin
    dchris_med24-Apr-08 15:13
    memberdchris_med24-Apr-08 15:13 
    GeneralExcellent job!!! Pin
    kevindu9-Jan-03 15:00
    memberkevindu9-Jan-03 15:00 
    QuestionKeyboard navigation? Pin
    Anonymous1-Nov-02 23:06
    sussAnonymous1-Nov-02 23:06 
    Generaldynamic delete tabs Pin
    silverspoon24-Jul-02 23:01
    membersilverspoon24-Jul-02 23:01 
    GeneralRe: dynamic delete tabs Pin
    Anonymous2-Aug-02 1:54
    sussAnonymous2-Aug-02 1:54 
    QuestionHow to set the caption dynamically ? Pin
    Kumar119-Feb-02 18:40
    memberKumar119-Feb-02 18:40 
    AnswerRe: How to set the caption dynamically ? Pin
    minuo22-Mar-02 10:38
    memberminuo22-Mar-02 10:38 
    GeneralRe: How to set the caption dynamically ? Pin
    Anonymous19-Sep-02 9:02
    sussAnonymous19-Sep-02 9:02 
    Generalno tabs Pin
    AMW9-Nov-01 20:31
    memberAMW9-Nov-01 20:31 
    GeneralMore instructions please Pin
    Anonymous21-Sep-01 5:17
    memberAnonymous21-Sep-01 5:17 
    GeneralRe: More instructions please Pin
    Rabentochter25-Jul-02 23:47
    memberRabentochter25-Jul-02 23:47 
    QuestionHow can I do to transfert datas ? Pin
    youssef24-Aug-01 1:08
    memberyoussef24-Aug-01 1:08 
    AnswerRe: How can I do to transfert datas ? Pin
    chhlud22-Apr-03 7:17
    memberchhlud22-Apr-03 7:17 
    GeneralRe: How can I do to transfert datas ? Pin
    youssef22-Apr-03 7:33
    memberyoussef22-Apr-03 7:33 
    GeneralRe: How can I do to transfert datas ? Pin
    chhlud23-Apr-03 3:11
    memberchhlud23-Apr-03 3:11 
    GeneralRe: How can I do to transfert datas ? Pin
    Yohome9-Jun-03 8:21
    memberYohome9-Jun-03 8:21 
    GeneralRe: How can I do to transfert datas ? Pin
    youssef9-Jun-03 8:23
    memberyoussef9-Jun-03 8:23 
    GeneralRe: How can I do to transfert datas ? Pin
    Yohome9-Jun-03 8:32
    memberYohome9-Jun-03 8:32 
    AnswerRe: How can I do to transfert datas ? Pin
    fabioo6-May-03 6:33
    memberfabioo6-May-03 6:33 
    GeneralRe: How can I do to transfert datas ? Pin
    seedy21-May-03 7:16
    sussseedy21-May-03 7:16 
    QuestionCan I get the sample project with FORMVIEW (not dialog based)? Pin
    Anonymous26-May-01 23:23
    memberAnonymous26-May-01 23:23 
    AnswerRe: Can I get the sample project with FORMVIEW (not dialog based)? Pin
    allex23-Jun-01 1:53
    memberallex23-Jun-01 1:53 
    GeneralRe: Can I get the sample project with FORMVIEW (not dialog based)? Pin
    Anonymous24-Jul-01 13:01
    memberAnonymous24-Jul-01 13:01 
    GeneralRe: Can I get the sample project with FORMVIEW (not dialog based)? Pin
    AMW24-Aug-01 4:15
    memberAMW24-Aug-01 4:15 
    GeneralRe: Can I get the sample project with FORMVIEW (not dialog based)? Pin
    tkha7-Nov-01 16:02
    membertkha7-Nov-01 16:02 
    GeneralSpawn a new window Pin
    Anonymous27-Apr-01 12:38
    memberAnonymous27-Apr-01 12:38 
    GeneralRe: Spawn a new window Pin
    Anonymous20-Aug-01 3:30
    memberAnonymous20-Aug-01 3:30 
    GeneralUse class with existing Property Sheet Pin
    Bob Eastman14-Apr-01 17:51
    memberBob Eastman14-Apr-01 17:51 
    GeneralThree Improvements Pin
    Darren S. Gonzales15-Feb-01 11:30
    memberDarren S. Gonzales15-Feb-01 11:30 
    GeneralRe: Three Improvements Pin
    Anonymous3-Jul-01 14:42
    memberAnonymous3-Jul-01 14:42 
    GeneralRe: Three Improvements Pin
    lpvoid6-Nov-02 4:18
    memberlpvoid6-Nov-02 4:18 
    GeneralRe: Three Improvements Pin
    lpvoid6-Nov-02 4:20
    memberlpvoid6-Nov-02 4:20 
    GeneralThe tabclass control cannot be used on already created dialogs by MFC wizards. Pin
    Bulent Ozkir31-Jan-01 2:43
    memberBulent Ozkir31-Jan-01 2:43 
    GeneralRe: The tabclass control cannot be used on already created dialogs by MFC wizards. Pin
    Mark Beifuss10-Oct-01 6:20
    memberMark Beifuss10-Oct-01 6:20 
    GeneralThe tabclass control cannot be used on already created dialogs by MFC wizards. Pin
    Bulent Ozkir31-Jan-01 2:42
    memberBulent Ozkir31-Jan-01 2:42 
    GeneralOnsize when showing dialog Pin
    Matt Philmon4-Oct-00 8:50
    sussMatt Philmon4-Oct-00 8:50 
    GeneralRe: Onsize when showing dialog Pin
    Matt Philmon4-Oct-00 11:58
    sussMatt Philmon4-Oct-00 11:58 
    GeneralRe: Onsize when showing dialog Pin
    Corey25-Apr-02 15:06
    memberCorey25-Apr-02 15:06 
    QuestionTab not visible? Pin
    Goh26-Sep-00 7:33
    sussGoh26-Sep-00 7:33 
    AnswerRe: Tab not visible? Pin
    Matt Philmon2-Oct-00 17:24
    sussMatt Philmon2-Oct-00 17:24 

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