Virtual Developer Workshop: Containerized Development with Docker

Sample Image

When I first got in touch with the Microsoft VC, it was boring to put a tab control in a form or in a dialog. I had to create the dialogs, fill in the TCITEM struct for each of my tabs, and finally insert them in the tab control. With the CXTabCtrl what you have to do is ilustrated 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 had to implement in the dialog (or form), to show the correct dialog, now is in the CXTabCtrl, so you don't have to worry about it. You can disable a tab too, so the user cannot see it's contents.
m_tabctrl.EnableTab(1 /*index*/, FALSE);

Also, you can set the following colors:

  • Selected tab
  • Unselected tab
  • Disabled tab
  • A mouse over tab


Download demo project - 19Kb

Download source - 4Kb


  • Great Job

    Posted by Legacy on 09/02/2002 07:00am

    Originally posted by: S.P.Rewatkar

    This code help me a lot.

  • How to use keyboard navigation in attached PropertyPages?

    Posted by Legacy on 06/25/2002 07:00am

    Originally posted by: Ray A. Akey

    How can I make it so that the TAB key changes the focus from the current control in an attached property page to the "next" control in that same property page?

    Currently, hitting TAB only make the focus change from the control that currently has focus, to the TAB control.

    How do I make the focus go to a different control? e.g. TAB cycle focus through ALL the controls on the dialog and then, finally, to the TAB control?

  • Simplified Tab Creation Process

    Posted by Legacy on 06/20/2002 07:00am

    Originally posted by: John Alexiou

    This class needs the following code in OnInitDialog()
    CXTabCtrl tabCtrl;
    mytab = new CMyTab;
    mytab->Create( CMyTab::IDD, &tabCtrl);
    tabCtrl.AddTab( mytab, "A new tab",0);
    mytab->tabCtrlPtr = &tabCtrl

    I think there is a lot of redundancy in this and if you have a lot of tabs
    keeping up with the pointers to CMyTab classes is a bit of a hasle.
    What I want is to have simple statements like this:

    tabCtrl.AddTab<CMyTabNew>("A new tab",0);
    tabCtrl.AddTab<CMyTabOther>("Another tab",0);
    tabCtrl.AddTab<CMyTabLast>("The last tab",0);

    where CMyTab... are the classes for the forms that are going to be
    displayed in the Tab Control.

    My solution adds the following member to CXTabCtrl
    vectorPtr<CDialog> forms;

    and the following method to CXTabCtrl

    template<typename F>
    void AddTab(LPTSTR lpszCaption, int iImage =0)
    const int item = forms.AddLink(new F() );
    ((F *)forms[item])->Create( F::IDD, this);
    AddTab( forms[item], lpszCaption, iImage);
    ((F *)forms[item])->tabCtrlPtr = this;

    all that is left is a class for a vector of pointers with automatic delete such as:

    struct DeletePtr {
    template<typename T>
    void operator()(const T * ptr) const { delete ptr; }

    template<typename R>
    class vectorPtr : public std::vector<R *> {
    virtual ~vectorPtr()
    std::for_each( begin(), end(), DeletePtr() );
    int AddLink(R * rval)
    std::vector<R *>::push_back(rval);
    return (int)base::size()-1;

    As a result the Main Form Destructor does not need to explicitly delete
    the pointers to CMyTab...classes as in the original CXTabCtrl

    the only requerement on CMyTab (a form class for the tab) is that it contains
    a member for access to the Tab Control

    class CMyTab : public CDialog {
    CXTabCtrl * tabCtrlPtr;

  • no tabs

    Posted by Legacy on 11/10/2001 08:00am

    Originally posted by: AMW

    I'm pretty sure I've entered everything in right and my program builds and runs, but I have no tabs on my tab control.
    I'm writing an SDI app with a formview in a splitter window,
    and I can see the tab control in my formview and everthing, but I have no tabs.
    I'm still kinda new to MFC and any kind of help would really be appreciated.

  • I wana get a sample project with FORMVIEW.

    Posted by Legacy on 05/27/2001 07:00am

    Originally posted by: baldr

    I've a problem in selecting tabs in menu command.

  • how to remove flicker ?

    Posted by Legacy on 04/20/2001 07:00am

    Originally posted by: troggan

    i want to use this in a resizable-dialog. but this is flickering terrible. how can i work around that?


  • Hitting "escape" does not cause dialog to shut down...

    Posted by Legacy on 05/12/2000 07:00am

    Originally posted by: Paul

    I'm using the tab class, but when the user hits "escape" the dialog does not shut down.....is there anything I need to do to make this work??

  • How to navigate between tabs using hot keys

    Posted by Legacy on 04/13/2000 07:00am

    Originally posted by: Akhilesh


    Is there any way to navigate between tabs,
    using Hot keys like Ctrl + Tab.


  • Problem with Tabs in DLL

    Posted by Legacy on 03/21/2000 08:00am

    Originally posted by: Twist

    I use your CXTabCtrl class, which is really good, but I have a problem to use it into DLL.
    In fact, it's when the application runs the DoDataExchange function, the GetDlgItem doesn't. I tried to use an independant pointer, and not a Claas member of AppWizzard, but the problem is the same : GetDlgItem returns NULL pointer.

    If you got a soution, It would be really great. Otherwise, tell it to me.

    Thanks in advance

  • Dialog don't appear in the TabCtrl !!

    Posted by Legacy on 03/15/2000 08:00am

    Originally posted by: cyril

    The Control is really Good, but I have a problem. When I run my program, the Dialog I wanted to put into the TaCtrl appear in the top-left corner of the Screen.

    When I change the tab, the Dialog Changes too !!

    It's like if it was working, but the Dialogs are not in the TabCtrl

    Thanks for your reponse

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date