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

A simple tab like dialog control

, 31 Aug 2003
Rate this:
Please Sign up or sign in to vote.
CTabDialog bundles buttons and dialogs, so users can add their owner draw buttons and dialogs

Sample Image - TabDialog.gif


Nowadays dialog based applications are becoming more and more popular. To make my future development for dialog based application easier I worked out this CTabDialog, which operates like a Tab control, but gives you more chance to have your owner draw buttons and dialogs added. Hopefully CTabDialog will make your development of dialog based application easier.

Using the code

To use the class

  • Include the class to your application
  • Add the CTabDialog data member to your application:
        CTabDialog* m_pTabDialog;
  • In OnInitDialog() of your application, initialize the CTabDialog
    //create the TabDialog
    m_pTabDialog = new CTabDialog(IDD_TABDLG, this);
    if (m_pTabDialog->Create(IDD_TABDLG, this) == FALSE)
        return FALSE;
    //set the TabDialog's positon
    m_pTabDialog->SetWindowPos(this, rect.left,, 0 , 0,

    Note: you need to create a dialog resource for the CTabDialog control.

  • You then need to add pages to the control
    //Add pages (include button and dialog) to TabDialog
    BOOL CTabDialogTestDlg::AddPagesToTabDialog()
        //create first button
        m_pBtnOne = new CButton();
        RECT rectOne;
        rectOne.left = BTNONE_LOCATION.x;
        rectOne.bottom = BTNONE_LOCATION.y+BUTTON_HEIGHT;
        m_pBtnOne->Create("One", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectOne,
            m_pTabDialog, BUTTON_ONE);
        //create first dialog
        m_pPageOne = new CPageOneDlg(m_pTabDialog);
        if (m_pPageOne->Create(IDD_PAGE_ONE, m_pTabDialog) == FALSE)
            return FALSE;
        //add first page
        m_pTabDialog->AddPage(m_pPageOne, m_pBtnOne);
        //Create second button
        m_pBtnTwo = new CButton();
        RECT rectTwo;
        rectTwo.left = BTNTWO_LOCATION.x;
        rectTwo.bottom = BTNTWO_LOCATION.y+BUTTON_HEIGHT;
        m_pBtnTwo->Create("Two", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectTwo,
            m_pTabDialog, BUTTON_TWO);
        //create second dialog
        m_pPageTwo = new CPageTwoDlg(m_pTabDialog);
        if(m_pPageTwo->Create(IDD_PAGE_TWO, m_pTabDialog) == FALSE)
            return FALSE;
        //add second page
        m_pTabDialog->AddPage(m_pPageTwo, m_pBtnTwo);
        //Create third button
        m_pBtnThree = new CButton();
        RECT rectThree;
        rectThree.left = BTNTHREE_LOCATION.x;
        rectThree.bottom = BTNTHREE_LOCATION.y+BUTTON_HEIGHT;
        m_pBtnThree->Create("Three", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
            rectThree, m_pTabDialog, BUTTON_THREE);
        //create third dialog
        m_pPageThree = new CPageThreeDlg(m_pTabDialog);
        if(m_pPageThree->Create(IDD_PAGE_THREE, m_pTabDialog) == FALSE)
            return FALSE;
        //add third page
        m_pTabDialog->AddPage(m_pPageThree, m_pBtnThree);
        return TRUE;
  • You then need to call InitPagesShow() member function of CTabDialog to set the default showing of the control.
    //initialize the showing of TabDialog


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

Wang Yingwu
Web Developer
Singapore Singapore
No Biography provided

Comments and Discussions

QuestionMemory leak Pinmembermsopengl10-Oct-11 19:26 
GeneralGreat work! Pinmemberxtjie21-Nov-10 22:52 
Generalquestion about create a dlg Pinmemberhusoso25-Feb-08 16:55 
QuestionHow to get SetFocus Pinmembersheshidar26-Sep-07 21:45 
Generalou very much for this beautifull article.How to get SetFocus Pinmembersheshidar26-Sep-07 21:41 
QuestionHow change the position of the button? and add new one? Pinmemberfreddy1ca29-Aug-04 11:38 
AnswerRe: How change the position of the button? and add new one? Pinmemberhusoso25-Feb-08 19:50 
GeneralXie xie Wang Yingwu! PinmemberGray Dragon8-Jan-04 19:47 
GeneralChange tab without really click the button Pinsussycjack29-Nov-03 17:34 
GeneralRe: Change tab without really click the button Pinmemberprakashjagdale11-Jan-04 4:20 
GeneralProject file missing Pinmembersmesser2-Sep-03 11:59 
GeneralRe: Project file missing PinmemberWang Yingwu2-Sep-03 16:38 
GeneralRe: Project file missing PinadminChris Maunder2-Sep-03 17:14 
GeneralRe: Project file missing PinmemberWang Yingwu2-Sep-03 17:18 
GeneralMemory leak!!! PinmemberGrant Chan15-Aug-03 19:47 
GeneralRe: Memory leak!!! PinmemberWang Yingwu31-Aug-03 23:24 
GeneralInteresting! PinmemberWREY13-Jun-03 9:48 
GeneralRe: Interesting! PinadminChris Maunder16-Jun-03 14:08 
GeneralRe: Interesting! PinmemberWang Yingwu31-Aug-03 23:28 

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.150123.1 | Last Updated 1 Sep 2003
Article Copyright 2003 by Wang Yingwu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid