Download source files - 11 Kb
Download demo project - 21 Kb

Credits And Acknowledgments
First of all I like to Credit the Original Authors on the
fantastic control that they have developed using MFC. Looking at the source code
the following names are mentioned.
- Ian Brumby
- Phil Baxter
- Kirk Stowell
Overview
- I needed a FlatTabCtrl to use in a ATL/WTL project, I noticed that the
KPad article on codeproject http://www.codeproject.com/wtl/kpad.asp
had something similar, but it was not what I was looking for. My attention
then turned to Flat Tab Controls that were MFC based and this article basically ports the
CFlatTabCtrl. Two ATL
files contain the port.
- atlflattab.h (Contains the main
CFlatTabCtrl Class
for WTL)
- atlmetafilebutton.h (used by the
CFlatTabCtrl Class)
Requirements
You will require the WTL Libraries, these can be
downloaded from the Microsoft site. There are various articles on the net that
tell you how to do this, so I won't bore you with the details.
Note - This control uses the WTL CString class and the
STL std::list template class.
How to use the control in your WTL App
1. Make sure you have the following ATL files included in
your stdafx.h
- atlwin.h
- atlctrls.h
- atlmisc.h
atlmisc.h is required as it has the definition for the WTL CString Class
2. Add the header file atlflattab.h to the Dialog or view source code that
will be using the control.
3. Create the control in the OnInitDialog function e.g.
if (!m_FlatTabCtrl.Create(m_hWnd, rect, NULL, WS_VISIBLE | WS_CHILD | FTS_HASARROWS | FTS_BOTTOM | TCS_TOOLTIPS,
0, IDC_FLATTAB))
{
DWORD dErrorCode = GetLastError();
}
If you do not want the tool tip to display, then remove the
TCS_TOOLTIPS style
4. Use the Method InsertItem to add tabs to the
control.
m_FlatTabCtrl.InsertItem(0, " A ");
5. If you require tool tips, then you must route the
window messages to this control. This can be achieved by routing the controls
PreTranslateMessage Method through the dialogs PreTranslateMessage
functionality.
virtual BOOL PreTranslateMessage(MSG* pMsg)
{
m_FlatTabCtrl.PreTranslateMessage(pMsg); return IsDialogMessage(pMsg);
}
6. To receive events when the tab has been selected
add the OnNotify Macro to the message Map.
MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
In the OnNotify handler, trap the Events.
LRESULT OnNotify(UINT , WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
ATLASSERT(::IsWindow(m_hWnd));
NMHDR* pNMHDR = (NMHDR*)lParam;
LRESULT lResult = 0;
if(IDC_FLATTAB == (UINT)wParam)
{ sBuff.Format("Selected Tab Index %d", nChoice); MessageBox(sBuff, "Test App"); break; default: bHandled = FALSE;
CString sBuff;
int nChoice;
switch(pNMHDR->code)
{ case TCN_SELCHANGING:
break; case TCN_SELCHANGE:
nChoice = m_FlatTabCtrl.GetCurSel(); break;
} }
}
The Demo App shows how to use the control on a WTL
dialog class.