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

Sheet Tab View

, 1 Aug 2002
Rate this:
Please Sign up or sign in to vote.
Create your own sheet tab view like the output window in MS Dev Studio
<!-- Download Links --> <!-- Article image -->

Sample Image - sheettabwithscroll.jpg

<!-- Add the rest of your HTML here -->

Introduction

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

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.

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.SetFont(m_Font); 
        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(0,_T("Build")); 
        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(4,_T("Results"));
        m_ctlSheet.GetFlatTabCtrl()->InsertItem(5, _T("SQL Debugging"));
        m_ctlSheet.SetViewScrollRange(0, 1000, 100);
    
        WriteLotsofText();
    
        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

    MESSAGE_HANDLER(WM_HSCROLL, OnHScroll)

    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.

    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)
        { 
            CString sBuff; 
            int nChoice; switch(pNMHDR->code)
            {
                case TCN_SELCHANGING:
                    break;
                case TCN_SELCHANGE:
                    nChoice = m_ctlSheet.GetFlatTabCtrl()->GetCurSel();
                    sBuff.Format("Selected Tab Index %d", nChoice);
                    if (nChoice == 1)
                        WriteLotsofText();
                    else
                        m_ctlEdit.SetWindowText(sBuff);
                    break;
                default:
                    bHandled = FALSE;	// not handled
            }
        }
    
        return lResult;
    }

That's It

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

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

 
QuestionUse within MFC MDI application PinmemberBruce Warmer7-Aug-06 6:08 
Generalexcellent!but... PinmemberPole29-Mar-03 15:06 
QuestionCan this work m_ctlEdit.ShowScrollBar(SB_HORZ, FALSE) for a CListViewCtrl derived class PinmemberJose Cruz6-Nov-02 10:01 
GeneralSuggestion... Pinmembersedonya14-Aug-02 23:30 
GeneralThank you Rashid PinmemberRamon Casellas2-Aug-02 9:26 
GeneralCool PinmemberNorm Almond2-Aug-02 7:45 

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.140709.1 | Last Updated 2 Aug 2002
Article Copyright 2002 by Rashid Thadha
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid