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

Sheet Tab View

0.00/5 (No votes)
1 Aug 2002 3  
Create your own sheet tab view like the output window in MS Dev Studio

Sample Image - sheettabwithscroll.jpg

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