Sheet Tab View






3.22/5 (3 votes)
Aug 2, 2002
2 min read

97756

3220
Create your own sheet tab view like the output window in MS Dev Studio
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
You will need to include atlmisc.h in your stdafx.h file.
Create a view class similar to
CSheetTabWithScrollView
. If you do not require aCEdit
control, replace this with the control of your choice. Create theCSheetTabWindow
control and main view control (e.g.CEdit
) on theOnCreate
method, then re-size them on theOnSize
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 usingShowScrollBar
.Add the sheet tabs using
GetFlatTabCtrl()->InsertItem(..)
Handle the Scrolling events for your main control by adding the
OnHScroll
macro to the message mapMESSAGE_HANDLER(WM_HSCROLL, OnHScroll)
In the
OnHScroll
handler, Scroll your main controlLRESULT 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; }
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 eventsLRESULT 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.