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

Disable CTabCtrl tab items in WTL - Using the Owner Drawn Method

, 17 Jul 2002
Rate this:
Please Sign up or sign in to vote.
A port of Paul Dilascia MFC CTabCtrlWithDisable to WTL
<!-- Article image -->

Sample Image - atldisabledtabctrl.jpg

<!-- Add the rest of your HTML here -->


I needed a tab control that would allow me to enable and disable certain tab items, I did a search and came across the Paul Dilascia CTabCtrlWithDisable article. This was exactly what I required except that it was written in MFC. This article basically convert his code to WTL.

For more infomation on Paul Dilascia original article see here


You will require the WTL Libraries, these can be downloaded from the Microsoft site. There are various articles on the net that tell you how to do this, so I won't bore you with the details.

How to use the control in your WTL App

  1. Add the header file atlTabCtrlWithDisable.h to the Dialogs source code that will be using the control. The control class name is CTabCtrlWithDisable. You will also need to add atlmisc.h in your stdafx.h file.
  2. You will need to override the base class CTabCtrlWithDisable and set the pure virtual function IsTabEnabled e.g.
  3. class CMyTabCtrlWithDisable : public CTabCtrlWithDisable 
       BOOL IsTabEnabled(int nTab) 
          return (nTab !=2);

    Note - The isTabEnabled function determines which Tab gets disabled

    More information on the design of this class - see original article

  4. Instantiate the class and Subclass the control in the OnInitDialog function e.g.
    CString sBuff;
    m_ctlTab.SubclassDlgItem(IDC_TAB1, *this); 
    TCITEM item = { 0 }; 
    item.mask = TCIF_TEXT; 
    sBuff = _T("Tab 1"); 
    item.pszText = sBuff.GetBuffer(sBuff.GetLength()); 
    m_ctlTab.InsertItem(0, &item); 
    sBuff = _T("Tab 2"); 
    item.pszText = sBuff.GetBuffer(sBuff.GetLength()); 
    m_ctlTab.InsertItem(1, &item); 
    sBuff = _T("Tab 3"); 
    item.pszText = sBuff.GetBuffer(sBuff.GetLength()); 
    m_ctlTab.InsertItem(2, &item); 
    sBuff = _T("Tab 4"); 
    item.pszText = sBuff.GetBuffer(sBuff.GetLength()); 
    m_ctlTab.InsertItem(2, &item); 
    sBuff = _T("Tab 5"); 
    item.pszText = sBuff.GetBuffer(sBuff.GetLength()); 
    m_ctlTab.InsertItem(2, &item); 
  6. Call InitTabStatus method. Note the call to InitTabStatus, this function is called after inserting the tab items, and it basically does a check on the status of the tab items to see if any tab items need disabling.
  7. Add REFLECT_NOTIFICATIONS() to the end of the message map from your calling class.

That's it!!!

The Demo App shows how to use the control on a WTL dialog class.


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

Rashid Thadha
Web Developer
United Kingdom United Kingdom
Was made redundant in early 2003 after 10 years in computer programming, since then started my own business (selling computer books on the net)

Comments and Discussions

GeneralUse in MFC Pinmemberbreak;18-Oct-06 1:10 
GeneralUse TCS_VERTICAL style PinsussAsha Udupa21-Apr-05 19:48 
GeneralUpdate - DrawItem function PinmemberRashid Thadha15-Aug-02 0:59 
Use the following code to remove the white line when an Tab Item is selected.
void DrawItem(LPDRAWITEMSTRUCT lpdis)
    if (lpdis->itemID==-1)
        return; // If there are no list box items, skip this message. 
    // use draw item DC
    CDCHandle dc(lpdis->hDC);
    DRAWITEMSTRUCT& ds = *lpdis;
    int iItem = ds.itemID;
    // Get tab item info
    TCHAR text[512];
    TCITEM tci;
    tci.mask = TCIF_TEXT;
    tci.pszText = text;
    tci.cchTextMax = sizeof(text);
    GetItem(iItem, &tci);
    // calculate text rectangle and color
    CRect rc = ds.rcItem;
    rc += CPoint(1, 4);						 // ?? by trial and error
    CRect rect = ds.rcItem; += ::GetSystemMetrics(SM_CYEDGE);
    dc.FillSolidRect(rect, ::GetSysColor(COLOR_BTNFACE));
    // draw the text
    OnDrawText(dc, rc, text, !IsTabEnabled(iItem));

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
Web03 | 2.8.150327.1 | Last Updated 18 Jul 2002
Article Copyright 2002 by Rashid Thadha
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid