Click here to Skip to main content
13,398,905 members (36,373 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 6 Feb 2001

CFlatTabCtrl port to ATL/WTL

, 19 Feb 2001
Rate this:
Please Sign up or sign in to vote.
Full FlatTabCtrl using WTL
<!-- Link to source file download -->
  • Download source files - 11 Kb
  • <!-- Link to demo file download -->
  • Download demo project - 21 Kb
  • <!-- Article image -->

    Sample Image - ATLFlatTabCtrl.gif

    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


    I needed a FlatTabCtrl to use in a ATL/WTL project, I noticed that the KPad article on codeproject 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)


    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.

    // create the flat tab control.
    if (!m_FlatTabCtrl.Create(m_hWnd, rect, NULL, WS_VISIBLE | WS_CHILD | FTS_HASARROWS | FTS_BOTTOM | TCS_TOOLTIPS, 
    			  0, IDC_FLATTAB))
       DWORD dErrorCode = GetLastError();
       //Find out why. Check the Win32 Error codes in MSDN

    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.


    In the OnNotify handler, trap the Events.

    LRESULT OnNotify(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
       NMHDR* pNMHDR = (NMHDR*)lParam;
       LRESULT lResult = 0;
       // handle messages from the flat tab control itself
       if(IDC_FLATTAB == (UINT)wParam)
       {        sBuff.Format("Selected Tab Index %d", nChoice); MessageBox(sBuff, "Test App"); break; default: bHandled = FALSE; // not handled } } return lResult; }
          CString sBuff;
          int nChoice;
          {         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.


    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

    Rashid Thadha
    Web Developer
    United Kingdom United Kingdom
    Was made redundant in early 2003 after 10 years in computer programming, since then started my own business (selling computer books on the net)

    You may also be interested in...

    Comments and Discussions

    QuestionMFC version? Pin
    cristianb9-Jan-04 1:52
    membercristianb9-Jan-04 1:52 
    GeneralBug in DeleteAllItems() Pin
    Anatoly Ivasyuk26-Dec-01 20:33
    memberAnatoly Ivasyuk26-Dec-01 20:33 

    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
    Web02 | 2.8.180218.2 | Last Updated 20 Feb 2001
    Article Copyright 2001 by Rashid Thadha
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid