viksoe.dk

Cool Tab controls

Cool Tab controls


This article was submitted .


This WTL Cool Tabs class is not cool at all. In fact, it doesn't display anything!
It's a Tab control framework, adding support for the things Microsoft left out of the original common control: Custom draw support, insert- and delete-item notifications, position displacement and other fine features like that.

The control is actually a completely custom Control, which in its paint event sends out NM_CUSTOMDRAW notifications to its parent. It sends out CDDS_PREPAINT, CDDS_POSTPAINT and CDDS_ITEMPREPAINT events as most of the other common controls do.
So to draw your own custom tab control catch these reflected notifications either from a class derived from the generic CCustomTabCtrl or from the control's parent.

How to use it

Choose one of the sample Tab controls supplied:
  • CButtonTabCtrl - just like the TCS_BUTTONS style
  • CFolderTabCtrl - looks like the Developer Studio tab
  • CSimpleDotNetTabCtrl - a VisualStudio.NET look-alike
To use it, place a Tab control on your dialog.
Add it as a member variable to your dialog implementation file...
CFolderTabCtrl m_ctlTab
In the OnInitDialog() event handler, add the following line:
  LRESULT OnInitDialog(UINT /*uMsg*/, 
                       WPARAM /*wParam*/, 
                       LPARAM /*lParam*/, 
                       BOOL& /*bHandled*/)
  {
    ...
    m_ctlTab.SubclassWindow(GetDlgItem(IDC_TAB1));
    ...
  }
Add the following reflection macro to your main message map:
   BEGIN_MSG_MAP(CMainDlg)
      ...
      REFLECT_NOTIFICATIONS()
   END_MSG_MAP()

The CoolTab API behaves just like the original tab. There is almost a 1:1 match between API methods. It even passes the same Win32 structures as arguments. This doesn't mean that you can use the TabCtrl_InsertItem() and related Win32 methods, though - the control doesn't support receiving these messages yet. Just use the inline class methods (like you're used to do with the WTL CTabCtrl class). Support for SendMessage() would just take a few lines of additional code, but I'd like to keep it OO.

Modifications

Pascal Binggeli enhanced the XP looking tab control with images and a more perfect XP look. Get it here.

Daniel Bowen took up some of the work of Pascal Binggeli and added several new modifications to the tab control. This sample has a number of great enhancements and new controls. It's definitely worth a download.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 3.1 Library

Useful Links

Daniel Bowen's great WTL sample

Download Files

DownloadSource Code (11 Kb)

To the top