Click here to Skip to main content
13,633,601 members
Click here to Skip to main content
Add your own
alternative version


76 bookmarked
Posted 26 Jun 2000

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.

    You may also be interested in...


    Comments and Discussions

    QuestionAbout the license... Pin
    Member 106971855-Jul-16 21:58
    memberMember 106971855-Jul-16 21:58 
    QuestionMFC Tab Control Video Tutorials Pin
    Jack123sweet5-Apr-14 8:20
    memberJack123sweet5-Apr-14 8:20 
    AnswerRe: MFC Tab Control Video Tutorials Pin
    Vaughan Daniel13-May-14 10:02
    memberVaughan Daniel13-May-14 10:02 
    GeneralGetItem() failed! Pin
    Harly11-Jul-12 15:30
    memberHarly11-Jul-12 15:30 
    GeneralMy vote of 3 Pin
    fishpixie19-Mar-11 20:14
    memberfishpixie19-Mar-11 20:14 
    GeneralProposition Pin
    voy k16-May-06 20:11
    membervoy k16-May-06 20:11 
    GeneralAccess the edit control inside the tab Pin
    iulikii_026-Apr-06 2:46
    memberiulikii_026-Apr-06 2:46 
    Questionhow can i ................ Pin
    alupiv29-Mar-06 18:35
    memberalupiv29-Mar-06 18:35 
    QuestionHow to know which page is selected Pin
    cyberaoul5-Oct-05 22:47
    membercyberaoul5-Oct-05 22:47 
    QuestionHelp,how can i change it's size? Pin
    Lancelot Yuan10-Jul-05 15:33
    memberLancelot Yuan10-Jul-05 15:33 
    AnswerRe: Help,how can i change it's size? [modified] Pin
    pajero_pn11-Jan-08 21:40
    memberpajero_pn11-Jan-08 21:40 
    1. Change declaration XTabCtrl.h
    void ChangeTab(int iIndex, CWnd *pNewTab, LPTSTR lpszCaption, int iImage, int newWidth, int newHeight);

    2. Change XTabCtrl.cpp
    void CXTabCtrl::ChangeTab(int iIndex, CWnd *pNewTab, LPTSTR lpszCaption, int iImage, int newWidth, int newHeight)
    pNewTab->SetWindowPos(NULL, m_ptTabs.x, m_ptTabs.y , newWidth, newHeight, SWP_FRAMECHANGED | SWP_NOZORDER);

    3. Example, new declaration, you *.h:
    bool fChange=false;
    CPomoc* m_pPOMOC; //new class for TAB (new dialog window, child)
    // Dialog Data
    enum { IDD = IDD_....._DIALOG };
    CXTabCtrl m_cTAB; //you TabCtrl

    4. Example, OnInitDialog....

    m_pPOMOC = new CPomoc; //new class
    m_pPOMOC -> Create(CPomoc::IDD, &m_cTAB);
    m_pPOMOC -> m_pTab = &m_cTAB;

    5. Example, procedure:
    void .......OnSize(UINT nType, int cx, int cy)
    CDialog::OnSize(nType, cx, cy);

    if (nType==SIZE_MAXIMIZED) //Window has been maximized.
    m_cTAB.SelectTab(iIndex); //always first before "ChangeTab", as no.1
    m_cTAB.ChangeTab(iIndex,m_pPOMOC,"Titel",0,myWidth-18,myHeight-42); //resize declaration this TAB, as no.2
    m_cTAB.MoveWindow(x,y,myWidth-12,myHeight-12,TRUE); //resize this TAB (windows)
    Invalidate(FALSE); //OnPaint

    // myWidth and myHeight you must calculations....
    // warning: no.1 and no.2 repeated for all Tab (this example is only one Tab)!

    6. Example, new class CPomoc, procedure:
    void CPomoc::OnPaint()
    CPaintDC dc(this); // device context for painting
    if (fChange==true)
    //Example: m_cPOMOC as Edit Control (in CPomoc dialog) resize if window has been maximized.
    // Do not call CDialog::OnPaint() for painting messages

    modified on Wednesday, April 16, 2008 5:48 PM

    Generalprobleme whith CXTabCtrl Pin
    christophecrepin23-Jun-05 7:44
    memberchristophecrepin23-Jun-05 7:44 
    Generalhelp! How to get the value I set in tab control. Pin
    No-Cloud-Dagon23-Feb-05 15:20
    memberNo-Cloud-Dagon23-Feb-05 15:20 
    Generalbitmap couldn't move with SelectTab() Pin
    yenh12-Feb-04 13:41
    sussyenh12-Feb-04 13:41 
    GeneralProblem on Tab when enabled XP theme Pin
    Anonymous16-Nov-03 13:27
    sussAnonymous16-Nov-03 13:27 
    GeneralRe: Problem on Tab when enabled XP theme Pin
    Anonymous15-Jul-04 1:36
    sussAnonymous15-Jul-04 1:36 
    GeneralSub-Par Pin
    prairiedog2k@yahoo.com21-Aug-03 9:13
    memberprairiedog2k@yahoo.com21-Aug-03 9:13 
    GeneralMultiline Tab Pin
    Edwin1612613-Aug-03 0:04
    sussEdwin1612613-Aug-03 0:04 
    GeneralRe: Multiline Tab Pin
    pige25-Sep-07 1:49
    memberpige25-Sep-07 1:49 
    GeneralHelp - Blank after re-show Pin
    dragon7423-Jul-03 5:43
    memberdragon7423-Jul-03 5:43 
    GeneralDoesn't look good on WinXP Pin
    Mirzallica6-Jul-03 14:09
    sussMirzallica6-Jul-03 14:09 
    GeneralDrag and Drop in a tab Control dialog Pin
    Yohome10-Jun-03 2:30
    memberYohome10-Jun-03 2:30 
    Generalonsize problem... Pin
    opcode11272-Jun-03 21:00
    memberopcode11272-Jun-03 21:00 
    GeneralBug: Inhibit Hot key Pin
    ericlts7-May-03 19:50
    memberericlts7-May-03 19:50 
    GeneralPlease Help me!! Pin
    Ansonku1-May-03 4:04
    memberAnsonku1-May-03 4:04 

    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.

    Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
    Web04 | 2.8.180712.1 | Last Updated 27 Jun 2000
    Article Copyright 2000 by xicoloko
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid