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

A WTL Tab Control for Managing Tab Views

, 21 Jun 2002
Rate this:
Please Sign up or sign in to vote.
This article describes a tab control that automates the management of tab windows.

TabViewCtrl Demo Image


If you are looking for general information about tab controls, you are in the wrong place. You can find general information about tab controls elsewhere (MSDN). If you are just looking for an easier way to use tab controls in WTL, read on.


Tab controls are powerful tools, but sometimes it can be a hassle to re-implement tab management every time you need a tab control. This class encapsulates the functionality for managing tabs.

Some similar controls are available for MFC, but I could not find any tab management controls for WTL. This class was originally a port of an MFC class CSizingTabCtrlBar (author unknown), but as work progressed, the implementation changed significantly.

The management of the "View" windows for each tab is loosely based on the pane management for WTL::CSplitterImpl. Child "View" windows are created by the application for each tab and submitted to the CWTLTabViewCtrl for management.


To use this class in an SDI WTL application, derive a class from CWTLTabViewCtrl. (You need to have WTL in your include path to compile.)

class CDemoTabViewCtrl : public CWTLTabViewCtrl

    BOOL PreTranslateMessage(MSG* pMsg)
        return FALSE;


And declare it as a member variable on the main frame.

CDemoTabViewCtrl    m_TabViewDemo;


In a WTL SDI application, create the tab view window as a child of the main frame and assign the window handle to the m_hWndClient member variable.

m_hWndClient = m_TabViewDemo.Create( 
                      m_hWnd, rcDefault, NULL, 
                      WS_CHILD | WS_VISIBLE, WS_EX_STATICEDGE );

Adding a tab

To add a tab to the tab control, simply call CWTLTabViewCtrl::AddTab, passing the tab label, the window to manage and optionally the activation state, the image index, and the param to associate with the tab.

CTabDemoHelp    m_DemoTabHwnd;

// Create the tab as a child of the tab control
m_DemoTabHwnd.Create( m_hWndClient );

// Add the tab to the tab control
m_TabViewDemo.AddTab( "Tab Name", m_DemoTabHwnd );

Removing a tab

To remove a tab from the tab control, call CWTLTabViewCtrl::RemoveTab with the zero based index of the tab to remove..

// Remove the tab by specifying the zero based index of the 
// tab to remove
m_TabViewDemo.RemoveTab( theIndexOfTheTabToRemove );

CWTLTabViewCtrl::RemoveTab( ) does not destroy the window handle passed to CWTLTabViewCtrl::AddTab. This should be done when CWTLTabViewCtrl::RemoveTab() is called or when the window is no longer needed.

You can also override the CWTLTabViewCtrl::OnTabRemoved virtual method in the derived tab control class to destroy the window or any memory allocated for the window.

Usage in other scenarios

Using this class in a WTL MDI or WTL dialog application should be straightforward. Let me know how it goes Wink | ;-)

Modifying the tab control styles

To modify the styles of the tab control, call the CWTLTabViewCtrl::ModifyTabStyle( ) method. Using this method to set or remove the tab styles, TCS_BOTTOM, TCS_RIGHT and TCS_VERTICAL will set the font to the appropriate orientation.

Evidently, a tab control can handle tabs of different orientations, though it fails to modify the text used to draw the tab label to the proper orientation. The WM_SETFONT message is used to set the appropriate font.

Image Lists

Image lists can be associated with any tab control. These image lists are used to determine the image that appears on each tab. An optional parameter of the CWTLTabViewCtrl::AddTab() method specifies the zero based index of the image in the image list that should appear next to the tab label.

API Reference

All WTL::CTabCtrl methods are available on CWTLTabViewCtrl since the latter is derived from the former. The Windows Help file included with the source download contains a complete API reference, compliments of DOxygen (


In order for the tab view control to receive the TCN_SELCHANGE message that notifies the control that a new tab has been selected, parent windows must have the REFLECT_NOTIFICATIONS() macro in their message maps.


If the tab view window is a child of another window, such as CSplitterWindow, you can use the FORWARD_NOTIFICATIONS() macro to forward the WM_NOTIFY messages.


Demo Application

The demo application is a simple WTL SDI application that houses the tab view control. It allows you to add and remove tabs and dynamically change the style of the tab control.

This application dynamically allocates a window class and stores it as the param associated with the tab. When the tab is removed, it destroys the window and deletes the window class in the overloaded CWTLTabViewCtrl::OnTabRemoved virtual method. It uses the image index to determine the type of window to be deleted.


For updates to this class, visit Send me an email if you end up using this class.

  • 06/18/2002 - Creation.


This article and all accompanying material is ©2002 Stephen Jones. All rights reserved. The compiled source code may be used at will.



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

Stephen Jones
Web Developer
United States United States
Stephen Jones is a Lead Software Engineer for Anark Corporation in Boulder, Colorado.

Comments and Discussions

BugV607 Ownerless expression 'm_Views[inTab]'. wtltabviewctrl.h 226 PinmemberPPA_PPA4-Apr-13 21:38 
GeneralMy vote of 5 Pinmemberkevinhan408926-Mar-12 17:22 
Generalusing this control in WTL MDI project Pinmemberdeepdiverxx24-Oct-10 20:13 
GeneralCatch Tab key in TabViews Pinmembercact20-Nov-08 1:30 
GeneralRe: Catch Tab key in TabViews Pinmemberzhouyeheng22-Dec-08 4:18 
GeneralChild Windows Pinmemberanubis_ex30-Oct-07 6:55 
I have placed the control on docking windows implementation. but is still confuse where i use FORWARD_DECLARATION(), in child windows( but the docking control doesn´t handle MESSAGE_MAPS) or the class when CWTLTabViewCtrl was inherited??Sigh | :sigh:
Sigh | :sigh: Sigh | :sigh:
GeneralRe: Child Windows Pinmemberzhouyeheng22-Dec-08 4:19 
GeneralMDI Pinmemberpicazo4-Mar-06 17:32 
GeneralA error found when use TCS_MULTILINE style PinmemberRocom.liu27-Jan-05 17:50 
GeneralIncorrect link to demo app. Pinmemberblippblapp17-Nov-04 22:46 
GeneralA fix for problems when using in Dialog Pinsussmparedes25-Nov-03 13:43 
GeneralButtons in Tab Lock up App PinmemberBillisWrong20-Nov-03 7:44 
GeneralWonderful PinmemberShawnTassie7-May-03 17:41 

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
Web01 | 2.8.150326.1 | Last Updated 22 Jun 2002
Article Copyright 2002 by Stephen Jones
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid