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

CFlatTabCtrl port to ATL/WTL

By , 19 Feb 2001
Rate this:
Please Sign up or sign in to vote.
<!-- 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

    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.

    // 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.

           MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
    

    In the OnNotify handler, trap the Events.

    LRESULT OnNotify(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
       ATLASSERT(::IsWindow(m_hWnd));
       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;
          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.

    License

    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)
    www.pricecutbook.co.uk
     

    Comments and Discussions

     
    QuestionMFC version? Pinmembercristianb9-Jan-04 0:52 
    GeneralBug in DeleteAllItems() PinmemberAnatoly Ivasyuk26-Dec-01 19:33 

    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 | Mobile
    Web02 | 2.8.140415.2 | Last Updated 20 Feb 2001
    Article Copyright 2001 by Rashid Thadha
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Use
    Layout: fixed | fluid