5,427,303 members and growing! (17,085 online)
Email Password   helpLost your password?
Desktop Development » Tabs & Property Pages » Owner Drawn     Intermediate

A simple tab like dialog control

By Wang Yingwu

CTabDialog bundles buttons and dialogs, so users can add their owner draw buttons and dialogs
VC6, VC7, VC7.1, C++Windows, NT4, Win2K, WinXP, Win2003, MFC, VS6, Visual Studio, Dev

Posted: 12 Jun 2003
Updated: 31 Aug 2003
Views: 86,947
Bookmarked: 23 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
38 votes for this Article.
Popularity: 3.91 Rating: 2.47 out of 5
17 votes, 44.7%
1
1 vote, 2.6%
2
2 votes, 5.3%
3
3 votes, 7.9%
4
15 votes, 39.5%
5

Sample Image - TabDialog.gif

Introduction

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
    #include 
    
    "TabDialog.h"
    
  • Add the CTabDialog data member to your application:
    private:
        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, rect.top, 0 , 0,
        SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
    

    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.right = BTNONE_LOCATION.x+BUTTON_WIDTH;
        rectOne.top = BTNONE_LOCATION.y;
        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.right = BTNTWO_LOCATION.x+BUTTON_WIDTH;
        rectTwo.top = BTNTWO_LOCATION.y;
        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.right = BTNTHREE_LOCATION.x+BUTTON_WIDTH;
        rectThree.top = BTNTHREE_LOCATION.y;
        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
    
    m_pTabDialog->InitPagesShow();
    

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

About the Author

Wang Yingwu



Occupation: Web Developer
Location: Singapore Singapore

Other popular Tabs & Property Pages articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
Subject  Author Date 
Generalquestion about create a dlgmemberhusoso16:55 25 Feb '08  
GeneralHow to get SetFocusmembersheshidar21:45 26 Sep '07  
Generalou very much for this beautifull article.How to get SetFocusmembersheshidar21:41 26 Sep '07  
GeneralHow change the position of the button? and add new one?memberfreddy1ca11:38 29 Aug '04  
GeneralRe: How change the position of the button? and add new one?memberhusoso19:50 25 Feb '08  
GeneralXie xie Wang Yingwu!memberGray Dragon19:47 8 Jan '04  
GeneralChange tab without really click the buttonsussycjack17:34 29 Nov '03  
GeneralRe: Change tab without really click the buttonmemberprakashjagdale4:20 11 Jan '04  
GeneralProject file missingmembersmesser11:59 2 Sep '03  
GeneralRe: Project file missingmemberWang Yingwu16:38 2 Sep '03  
GeneralRe: Project file missingadminChris Maunder17:14 2 Sep '03  
GeneralRe: Project file missingmemberWang Yingwu17:18 2 Sep '03  
GeneralMemory leak!!!memberGrant Chan19:47 15 Aug '03  
GeneralRe: Memory leak!!!memberWang Yingwu23:24 31 Aug '03  
GeneralInteresting!memberWREY9:48 13 Jun '03  
GeneralRe: Interesting!adminChris Maunder14:08 16 Jun '03  
GeneralRe: Interesting!memberWang Yingwu23:28 31 Aug '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 31 Aug 2003
Editor: Nick Parker
Copyright 2003 by Wang Yingwu
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project