Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CFlatTabCtrl port to ATL/WTL

0.00/5 (No votes)
19 Feb 2001 1  
Full FlatTabCtrl using WTL
  • Download source files - 11 Kb
  • Download demo project - 21 Kb
  • 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