Click here to Skip to main content
13,296,374 members (54,834 online)
Click here to Skip to main content
Add your own
alternative version


296 bookmarked
Posted 29 May 2010


, 12 Jul 2010
Rate this:
Please Sign up or sign in to vote.
Adjustable contol with zooming and scrolling tabs, dragging with the mouse, custom drawing and much more
Sample Image


This control is based on CWnd class and can be placed as a child window anywhere, for example in the client area of the frame or dialog. Tabs can be top or bottom of child windows. The user can drag tabs using the mouse. Control has a zoom (shrink of tabs) and scrolling tabs mode. Also, if there is one tab the area of tabs can be hidden.

Using the Code

Child windows are added using their HWND and they can be of any type, for example modeless dialogs. TabCtrl consists of three areas: control area, tabs area, windows area.

Sample Image

To create the control and add elements to it, you can do the next steps:

TabCtrlEx<tabctrlstyle_vs2003_client /> m_TabCtrl;
CListCtrl m_List1, m_List2, m_List3;


// Creation and initialization of TabCtrl.
if(m_TabCtrl.Create(this,WS_CHILD | WS_VISIBLE,
  CRect(0,0,0,0),100/*id of TabCtrl*/)==false) return -1;

CImageList imagelist, imagelistSys;
CBitmap bmp, bmpSys;

imagelist.Create(16,16,ILC_COLOR24 | ILC_MASK,3,0);

imagelistSys.Create(14,14,ILC_COLOR24 | ILC_MASK,7,0);


// Creation of child windows.
      LVS_REPORT,CRect(0,0,0,0),&m_TabCtrl,2001)==0 ||
          LVS_REPORT,CRect(0,0,0,0),&m_TabCtrl,2002)==0 ||
   return -1;

// Initialization of child windows.
m_List1.InsertItem(0,_T("Mail 1"));
m_List2.InsertItem(0,_T("Calendar 1"));
m_List3.InsertItem(0,_T("Contact 1"));

// Attaching of child windows to the TabCtrl.
if(m_TabCtrl.Add(m_List1,_T("1.Mail"),0)==NULL ||
   m_TabCtrl.Add(m_List2,_T("2.Calendar"),1)==NULL ||
   return -1;

// Load state from registry and update.

Class TabCtrl not perform any rendering. For its drawing, it calls the functions of TabCtrlDraw interface. In general, to set the style TabCtrl you need to create an object inherited from interface ITabCtrlStyle and pass a pointer to it, using the function InstallStyle. This interface should provide a pointer to TabCtrlDraw for drawing, ITabCtrlRecalc to specify the size and spacing of their regions, ITabCtrlBehavior to correct the behavior of the control and ITabCtrlToolTip to define custom tooltip for the tabs and buttons. Object of class of style must exist during work of control. To do this, you can create an intermediate class like TabCtrlComplex. If you are working with only one style, then use the template class TabCtrlEx. The class name of the style is defined as a template parameter, for example:

TabCtrlEx<TabCtrlStyle_VS2003_client> m_TabCtrl;

Some styles have already been created. For example, styles similar to the tabs of working files and docking/floating panels in Visual Studio 2003, 2008 and 2010. To create your own styles, see classes TabCtrlStyle_VS2003_client, TabCtrlStyle_VS2003_bars, TabCtrlStyle_VS2008_client_classic, etc. Classes TabCtrlRecalcStub and TabCtrlBehaviorStub create a default implementation for the functions of ITabCtrlRecalc and ITabCtrlBehavior interfaces respectively. You can use them to create your own style objects.

Control requires a call of Update(true) after you add or delete tabs, as well as change its properties and state.

If the text of the tab is not fully visible and allowed tooltips (ToolTipEnable) and the mouse cursor is over the tab, then tooltip appears with its text. But if the function SetTabTooltipText was called, then the specified text is displayed always.

Control does not send messages to the parent window and uses an interface TabCtrlNotify for notification of the events. Use SetNotifyManager to set the pointer to your implementation of TabCtrlNotify.

By default, all drawing is based on double buffering, it excludes any blinking. If you want, use VirtualWindow::DoubleBuffering(false) to disable double buffering.

Good luck.


  • 28th May, 2010: Initial version
  • 10th June, 2010: Added redirect WM_NOTIFY message from child windows to a parent of the TabCtrl control
  • 12th June, 2010: Corrected error display of tooltips.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Borodenko Oleg
Software Developer Closed JSC 'Phazotron-7'
Belarus Belarus
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionVS2013 style Pin
jung-kreidler1-Dec-17 2:34
memberjung-kreidler1-Dec-17 2:34 
Question来自中国的朋友的问题 Pin
Member 1294799512-Jan-17 21:40
memberMember 1294799512-Jan-17 21:40 
QuestionControls on Child Dialog in TabControl Flickers on resize in VS2013 Any Solution? Pin
dijesh_ka31-Mar-16 1:34
memberdijesh_ka31-Mar-16 1:34 
QuestionGood work Pin
wdwcode18-Dec-14 3:11
memberwdwcode18-Dec-14 3:11 
QuestionGood Source Pin
37640838421-Nov-14 19:29
member37640838421-Nov-14 19:29 
AnswerRe: Good Source Pin
Borodenko Oleg22-Nov-14 21:44
memberBorodenko Oleg22-Nov-14 21:44 
QuestionGreat Work! But DDX_Control() problem. Pin
tuxxon2-Oct-14 3:48
membertuxxon2-Oct-14 3:48 
QuestionHow to send a message when the current tab changes Pin
Bob H23-Mar-14 6:52
memberBob H23-Mar-14 6:52 
AnswerRe: How to send a message when the current tab changes Pin
Borodenko Oleg23-Mar-14 10:11
memberBorodenko Oleg23-Mar-14 10:11 
Questioninsert multiple CDialog ' s with the same ID Pin
Ionut Codrut15-Feb-14 2:11
memberIonut Codrut15-Feb-14 2:11 
AnswerRe: insert multiple CDialog ' s with the same ID Pin
Borodenko Oleg17-Feb-14 3:59
memberBorodenko Oleg17-Feb-14 3:59 
GeneralRe: insert multiple CDialog ' s with the same ID Pin
Ionut Codrut17-Feb-14 18:30
memberIonut Codrut17-Feb-14 18:30 
QuestionGreat job,Vote of 10! Pin
lanmanck15-Aug-13 18:03
memberlanmanck15-Aug-13 18:03 
GeneralMy vote of 5 Pin
Herusetiyadi8-Jun-13 17:56
memberHerusetiyadi8-Jun-13 17:56 
GeneralMy vote of 5 Pin
noending7-May-13 5:33
membernoending7-May-13 5:33 
GeneralMy vote of 5 Pin
Albertino26-Apr-13 7:32
memberAlbertino26-Apr-13 7:32 
QuestionWould be the worlds best but... Pin
Areal Person21-Dec-12 12:20
memberAreal Person21-Dec-12 12:20 
AnswerRe: Would be the worlds best but... Pin
Borodenko Oleg23-Dec-12 5:51
memberBorodenko Oleg23-Dec-12 5:51 
AnswerRe: Would be the worlds best but... Pin
Borodenko Oleg25-Dec-12 2:20
memberBorodenko Oleg25-Dec-12 2:20 
Maybe my other article MultiPaneCtrl[^] is what you want?
Questionhello, about add DDX_Control(pDX, IDC_STATIC, m_picCtrl); run error Pin
dnybz6-Oct-12 0:30
groupdnybz6-Oct-12 0:30 
AnswerRe: hello, about add DDX_Control(pDX, IDC_STATIC, m_picCtrl); run error Pin
noending27-Oct-12 19:59
membernoending27-Oct-12 19:59 
QuestionHow to add a scroll bar if the inner dialog is very large Pin
Eversoft27-Sep-12 17:04
memberEversoft27-Sep-12 17:04 
AnswerRe: How to add a scroll bar if the inner dialog is very large Pin
Borodenko Oleg27-Sep-12 23:11
memberBorodenko Oleg27-Sep-12 23:11 
GeneralMy vote of 5 Pin
Jonathanrz25-Jul-12 4:08
memberJonathanrz25-Jul-12 4:08 
Questionenable only single tab on the control Pin
gaurish thakkar21-Jun-12 19:14
membergaurish thakkar21-Jun-12 19:14 
AnswerRe: enable only single tab on the control Pin
Borodenko Oleg21-Jun-12 20:26
memberBorodenko Oleg21-Jun-12 20:26 
QuestionCan you use it w/o attaching HWND to tab ? Pin
Sasa Kajic2-Feb-12 2:48
memberSasa Kajic2-Feb-12 2:48 
QuestionIt's so good source, and I have a little question. Pin
Member 850081720-Dec-11 17:07
memberMember 850081720-Dec-11 17:07 
AnswerRe: It's so good source, and I have a little question. Pin
Borodenko Oleg21-Dec-11 0:17
memberBorodenko Oleg21-Dec-11 0:17 
QuestionAwesome!! Pin
Yonghwi Kwon18-Nov-11 21:28
memberYonghwi Kwon18-Nov-11 21:28 
GeneralMy vote of 5 Pin
AlbertXiao17-Oct-11 1:04
memberAlbertXiao17-Oct-11 1:04 
GeneralMy vote of 5 Pin
duke.liu19-Aug-11 15:42
memberduke.liu19-Aug-11 15:42 
GeneralClose Button on Tab Pin
Dansveen15-Mar-11 8:16
memberDansveen15-Mar-11 8:16 
GeneralRe: Close Button on Tab Pin
Borodenko Oleg15-Mar-11 12:33
memberBorodenko Oleg15-Mar-11 12:33 
GeneralRe: Close Button on Tab Pin
hpking5-Jun-11 21:11
memberhpking5-Jun-11 21:11 
GeneralMy vote of 5 Pin
valenfour10-Feb-11 5:27
membervalenfour10-Feb-11 5:27 
GeneralRun-Time Check Failure #1 - cast to a smaller... Pin
valenfour19-Jan-11 12:09
membervalenfour19-Jan-11 12:09 
GeneralRe: Run-Time Check Failure #1 - cast to a smaller... Pin
Borodenko Oleg21-Jan-11 12:33
memberBorodenko Oleg21-Jan-11 12:33 
GeneralRe: Run-Time Check Failure #1 - cast to a smaller... [modified] Pin
valenfour10-Feb-11 5:26
membervalenfour10-Feb-11 5:26 
QuestionHow to add View to TabCtrl??? Pin
lxshanye18-Jan-11 23:08
memberlxshanye18-Jan-11 23:08 
AnswerRe: How to add View to TabCtrl??? Pin
Borodenko Oleg21-Jan-11 12:10
memberBorodenko Oleg21-Jan-11 12:10 
GeneralMy vote of 5 Pin
peinanh16-Jan-11 22:39
memberpeinanh16-Jan-11 22:39 
GeneralWow Pin
futurejo6-Jan-11 1:47
memberfuturejo6-Jan-11 1:47 
GeneralNice work! Missing a thing... Pin
apopa7-Nov-10 22:02
memberapopa7-Nov-10 22:02 
Generalgood work! Pin
linhai12320-Oct-10 17:58
memberlinhai12320-Oct-10 17:58 
GeneralMy vote of 4 Pin
VUnreal21-Sep-10 12:05
memberVUnreal21-Sep-10 12:05 
Generalit shows "fatal error LNK1120". Pin
muou5555523-Aug-10 21:32
membermuou5555523-Aug-10 21:32 
GeneralRe: it shows "fatal error LNK1120". Pin
Borodenko Oleg25-Aug-10 10:39
memberBorodenko Oleg25-Aug-10 10:39 
Generalvery good Pin
fele chen18-Aug-10 22:01
memberfele chen18-Aug-10 22:01 
Generalwhy not support CWnd ,CDialog? [modified] Pin
hui16826-Jul-10 10:24
memberhui16826-Jul-10 10:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 12 Jul 2010
Article Copyright 2010 by Borodenko Oleg
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid