Click here to Skip to main content
15,867,308 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 375.7K   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

     
    GeneralMultiline Tab Pin
    Edwin1612613-Aug-03 0:04
    sussEdwin1612613-Aug-03 0:04 
    GeneralRe: Multiline Tab Pin
    pige25-Sep-07 1:49
    pige25-Sep-07 1:49 

    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.