Disable Tab

This class provides enabling and disabling of items in a tab control. The main purpose of the class is to provide this functionality for property sheets, but I think it may work for tab controls in general (I have not tested this).

Anyway, to use the class, just include the source and header file into your project. Create a member variable of type CTabCtrlEx in your property sheet derived class. Then, in the OnInitDialog function of your property sheet class call the CTabCtrlEx install function:

BOOL CMyPropertySheet::OnInitDialog()
    BOOL bResult = CPropertySheet::OnInitDialog();

    // TODO: Add your specialized code here
    m_tab.Install( this );

To enable or disable items, call the EnableItem() function:

    m_tab.EnableItem( 0, FALSE );

I have not had time to thoroughly test this class, but the code is fairly well commented, so following it should not be very difficult if you have problems. Please send me any comments, feedback bug fixes, etc. Enjoy!

Download source files 7KB


  • Example project for this class?

    Posted by break; on 07/25/2008 10:15am

    Hello, does any one have a little sampleproject for me, i can't start my own :( ?! regard

  • Bug in multiple monitor systems

    Posted by srbrook on 05/11/2006 06:45am

    Clicking the tab does not work when the application is placed on a monitor with negative co-ordinates (ie to the left of the main monitor)
    Fix in OnSelchanging function by replacing
        CPoint point( LOWORD( lastPos ),  LOWORD( lastPos ) );
        CPoint point( lastPos );
    See MSDN documentation for GetMessagePos() for reason why not to use LOWORD and HIWORD with this function.

  • Excellent, but one problem though

    Posted by Legacy on 11/19/2003 12:00am

    Originally posted by: Yusuf

    Excellent class, but there is a problem. If another window is placed on top of the tabs and then moved, the tab headers are black. This after Annelies fix on row 108. Any solutions??

  • Excellent Class!!!

    Posted by Legacy on 05/28/2003 12:00am

    Originally posted by: Masudkhan

    Hi Kevin Lussier,

    This is rellay an amazing class.
    Actually I was looking for such class from a lomg time.
    I went thru a lot of other webpages. Infact a Microsoft has published a page on how to disable tabs, which is not as simple as this one.

    This really saved a lot of effort of mine.

    Thanks & Regards

  • Help!!! WinXP Bug

    Posted by Legacy on 02/03/2003 12:00am

    Originally posted by: Indivara

    I tried Rick Austin's bug fix for WinXP, but there 
    still seems to be a problem. It works fine when switching
    tabs with Ctrl + Tab, but clicking with the mouse causes
    the tabs to be drawn incorrectly. Anyone have the same
    problem, or am I doing something wrong?

    It is not clear where "else" part of

    108: if (g_xpStyle.IsAppThemed())

    is supposed to end. I tried several positions, but
    with the same result.

    Please help!

  • Doesn't work under some Win2K implementations

    Posted by Legacy on 12/11/2002 12:00am

    Originally posted by: Lynn Reid

    Just a warning.... I used this code to simplify disabling tabs. Works great in standard Win98, NT, and 2K installations. However, one of my clients has a Win2K installation modified from standard (in ways which I cannot reproduce). This code produces tabs which cannot be selected on her machine -- no matter if they're disabled or not. Sorry I can't provide more details as I can't debug on her machine...

  • XP Modifications

    Posted by Legacy on 11/14/2002 12:00am

    Originally posted by: Rick Austin

    I modified the painting of the tabs to detect the presence of XP themes. I used code from www.codesource.com called XPVisualStyle to determine if running under a theme and to paint the background accordingly. That source can be found at:

    Follow the instructions from that site to add xpvisualstyle to your project.

    The following changes were made to TabCtrlEx.cpp

    After line 106

    105: // Create a CRect
    106: CRect rect( lpd->rcItem );
    108: if (g_xpStyle.IsAppThemed())
    109: {
    110: RECT rc;
    111: HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"TAB");
    112: if(bIsEnabled)
    113: {
    114: g_xpStyle.DrawThemeBackground(hTheme, lpd->hDC,
    115: TABP_TABITEM, TIS_NORMAL, &rc, 0);
    116: }
    117: else
    118: {
    119: g_xpStyle.DrawThemeBackground(hTheme, lpd->hDC,
    120: TABP_TABITEM, TIS_DISABLED, &rc, 0);
    121: }
    122: g_xpStyle.CloseThemeData(hTheme);
    123: }
    124: else
    125: {
    126: // Draw the background
    127: CBrush* back_brush;
    128: COLORREF color;
    129: color = (COLORREF) GetSysColor(COLOR_3DFACE);
    130: back_brush = new CBrush(color);
    132: FillRect( lpd->hDC, rect, (HBRUSH)back_brush->m_hObject);

    Note: Lines 127 - 132 where added/modified prior to my XP changes. These changes corrected a color problem with the tabs, at least in my test environment.

    The following changes were made to center the text on each tab. After switching to XP the text ended up against the left side of the tab which did not look right.

    186: if ( bIsEnabled ) {
    187: // Set the text color for our hilight (remember the original color)
    188: origCol = SetTextColor( lpd->hDC, GetSysColor( COLOR_BTNTEXT ) );
    189: // Draw the text
    190: DrawText( lpd->hDC, buf, -1, rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
    191: }
    192: // Draw enabled
    193: else {
    194: // Set the text color for our hilight (remember the original color)
    195: origCol = SetTextColor( lpd->hDC, GetSysColor( COLOR_3DHILIGHT ) );
    196: // Draw the text
    197: DrawText( lpd->hDC, buf, -1, rect + CPoint(1,1), DT_SINGLELINE | DT_CENTER | DT_VCENTER );
    198: // Set the text color for our gray text
    199: SetTextColor( lpd->hDC, GetSysColor( COLOR_GRAYTEXT ) );
    200: // Draw the text
    201: DrawText( lpd->hDC, buf, -1, rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
    202: }

  • Problems with Windows XP

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

    Originally posted by: Julien

    When making an app XP Theme Style Compatible, the tab control is really badly drawn.

    When using the control on a XP System without the Theme Style enabled, the tab control has a white background.

  • Great class - saved me a lot of time

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

    Originally posted by: Paul S. Vickery

    Thanks for a great class - it has saved me a lot of time trying to figure out a way of removing/inserting pages, as it's impossible to insert pages, I can now just enable/disable pages.

  • Bug-Fix Question: Needs SendKillActive() still Parameter "nItem" ?

    Posted by Legacy on 07/22/1999 12:00am

    Originally posted by: Olaf Oelsner


    I think SendKillActive() doesnt need "nItem".

    Olaf Oelsner

  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Microsoft® Office 365 is a top choice for enterprises that want a cloud-based suite of productivity collaboration applications. With Office 365, you get access to Microsoft™ Office solutions practically anytime, anywhere, on virtually any device. It's a great option for current Microsoft users who can now build on their experience with Microsoft™ solutions while enjoying the flexibility of a cloud-based delivery. But even organizations with no previous investment in Microsoft will find that …

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

Most Popular Programming Stories

More for Developers

RSS Feeds

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