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 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);
m_ctlEdit.SetFont(m_Font);
m_ctlEdit.SetScrollRange(SB_HORZ, 0, 1000);
m_ctlEdit.SetScrollPos(SB_HORZ, 0);
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
.
Add the sheet tabs using GetFlatTabCtrl()->InsertItem(..)
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)
{
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 events
LRESULT OnNotify(UINT , WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
ATLASSERT(::IsWindow(m_hWnd));
NMHDR* pNMHDR = (NMHDR*)lParam;
LRESULT lResult = 0;
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;
}
}
return lResult;
}
That's It
The demo app shows you how to use this in full.