Click here to Skip to main content
15,125,972 members
Articles / Desktop Programming / WTL
Posted 1 Aug 2002


58 bookmarked

Sheet Tab View

Rate me:
Please Sign up or sign in to vote.
1.80/5 (2 votes)
1 Aug 20022 min read
Create your own sheet tab view like the output window in MS Dev Studio

Sample Image - sheettabwithscroll.jpg


I took the opportunity to expand the scope of one of my earlier articles based on the CFlatTabCtrl by creating a sheet tab view that looks similar to the output view in Microsoft Developer Studio. A new control called CSheetTabWindow encapsulates the CFlatTabCtrl, a splitter bar and the CScrollBar. This control (CSheetTabWindow) then can be used with the main view control (e.g. a CEdit control) to give a sheet tab view. The example enclosed uses a CEdit control with the sheet tabs (see CSheetTabWithScrollView).


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.

How to use the view in your WTL App

  1. You will need to include atlmisc.h in your stdafx.h file.

  2. Create a view class similar to CSheetTabWithScrollView. If you do not require a CEdit control, replace this with the control of your choice. Create the CSheetTabWindow control and main view control (e.g. CEdit) on the OnCreate method, then re-size them on the OnSize method.

    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
        LRESULT lRes = DefWindowProc(uMsg,wParam,lParam); 
        CRect rcPos(0, 0, 0, 0); 
        m_ctlEdit.Create(*this, rcPos, NULL, WS_CHILD | WS_CLIPSIBLINGS | 
                                             WS_VISIBLE | 
                                             ES_MULTILINE | ES_AUTOVSCROLL | 
                                             ES_AUTOHSCROLL | ES_WANTRETURN); 
        // set the scrolling information for the edit control
        m_ctlEdit.SetScrollRange(SB_HORZ, 0, 1000); 
        m_ctlEdit.SetScrollPos(SB_HORZ, 0); 
        // importnat - need to hide the scroll bar on the edit contol as we are 
        // going to use our own 
        m_ctlEdit.ShowScrollBar(SB_HORZ, FALSE);
        m_ctlSheet.Create(*this,rcPos, NULL,WS_CHILD| WS_VISIBLE);
        m_ctlSheet.GetFlatTabCtrl()->InsertItem(1, _T("Debug")); 
        m_ctlSheet.GetFlatTabCtrl()->InsertItem(2, _T("FindinFile 1")); 
        m_ctlSheet.GetFlatTabCtrl()->InsertItem(3, _T("FindinFile 2"));
        m_ctlSheet.GetFlatTabCtrl()->InsertItem(5, _T("SQL Debugging"));
        m_ctlSheet.SetViewScrollRange(0, 1000, 100);
        return lRes;

    You will need to set the scrolling information for your main control, simply use SetScrollRange for this purpose. Also note that you must hide the main control's scroll bar, this can be done using ShowScrollBar.

  3. Add the sheet tabs using GetFlatTabCtrl()->InsertItem(..)

  4. Handle the Scrolling events for your main control by adding the OnHScroll macro to the message map


    In the OnHScroll handler, Scroll your main control

    LRESULT OnHScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
        if (m_ctlSheet.m_hWnd)
            // Simply send the scrolling info to the edit control
            m_ctlEdit.SendMessage(uMsg, wParam, lParam);
        return 0;
  5. 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)
            CString sBuff; 
            int nChoice; switch(pNMHDR->code)
                case TCN_SELCHANGING:
                case TCN_SELCHANGE:
                    nChoice = m_ctlSheet.GetFlatTabCtrl()->GetCurSel();
                    sBuff.Format("Selected Tab Index %d", nChoice);
                    if (nChoice == 1)
                    bHandled = FALSE;	// not handled
        return lResult;

That's It

The demo app shows you how to use this in full.


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)

Comments and Discussions

QuestionUse within MFC MDI application Pin
Bruce Warmer7-Aug-06 7:08
MemberBruce Warmer7-Aug-06 7:08 
Generalexcellent!but... Pin
Pole29-Mar-03 16:06
MemberPole29-Mar-03 16:06 
QuestionCan this work m_ctlEdit.ShowScrollBar(SB_HORZ, FALSE) for a CListViewCtrl derived class Pin
Jose Cruz6-Nov-02 11:01
MemberJose Cruz6-Nov-02 11:01 
GeneralSuggestion... Pin
sedonya15-Aug-02 0:30
Membersedonya15-Aug-02 0:30 
GeneralThank you Rashid Pin
Ramon Casellas2-Aug-02 10:26
MemberRamon Casellas2-Aug-02 10:26 
GeneralCool Pin
NormDroid2-Aug-02 8:45
professionalNormDroid2-Aug-02 8:45 

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.