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



Comments

  • 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

    Reply
  • 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 ) );
    by
        CPoint point( lastPos );
    
    See MSDN documentation for GetMessagePos() for reason why not to use LOWORD and HIWORD with this function.

    Reply
  • 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??

    Reply
  • 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
    Masudkhan

    Reply
  • 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!

    Reply
  • 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...

    Reply
  • 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:
    
    http://www.codeproject.com/w2k/xpvisualstyle.asp

    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 );
    107:
    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);
    131:
    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: }

    Reply
  • 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.

    Reply
  • 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.

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

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

    Originally posted by: Olaf Oelsner

    Hi

    I think SendKillActive() doesnt need "nItem".

    Olaf Oelsner

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds