Tabbed views within a splitter window

This article presents a class which can be used to create
tabbed views within a splitter window. As a starting point,
I used Daniel Harth’s article
about tabbed views within frame windows (SDI frame window
or MDI child window).

Since splitter window dynamically creates a view object
(based on RUNTIME_CLASS information), tabbed window is
created in the same way. In order to perform the creation
of all the views (tabs) within a tab window, this class
contains a virtual function DoCreateView(…) which is
called from within a Create() member function that actually
creates a tab window. Default implementation of DoCreateView(…)
function simply asserts since the actual creation of all the
views is delegated to an overloaded function in the derived class.

Besides this technique, there are several other functions:

(1) virtual function called after the view (tab) is changed

(2) virtual function which is called to determine whether the
switch to another view is allowed or not (by default it is allowed)

(3) function to change the label in runtime

(4) several informational function to get the pointer to the
current view, get the current tab index, get the label etc.

Here is a pseudo code that shows how to use this class:

Declare a derived class specific to your project:


class TMyTab : public TVisualTabInSplitter
{
protected:
DECLARE_DYNCREATE(TMyTab)
public:
virtual ~TMyTab();
virtual void DoCreateView(CCreateContext *pContext);
};

Class implementation:


IMPLEMENT_DYNCREATE(TMyTab,TVisualTabInSplitter)

TMyTab::~TMyTab()
{
}

void TMyTab::DoCreateView(CCreateContext *pContext)
{
CreateView(Page 1, RUNTIME_CLASS(CTreeView), pContext);
CreateView(Page 2, RUNTIME_CLASS(CListView), pContext);
}

If you are creatng an SDI application, then use the
following code as a sample:


BOOL DerivedFromCFrameWnd::OnCreateClient(…, CCreateContext *pContext)
{
Splitter.CreateStatic(this,1,2);

Splitter.CreateView(0,0,RUNTIME_CLASS(TTreeView),CSize(150,0),pContext);
Splitter.CreateView(0,1,RUNTIME_CLASS(TMyTab),CSize(0,0),pContext);

return TRUE;
}

Of course, you could also use a nested splitter window.

I intend to design a tabbed views class that can be used as
a child to frame window and that can contain a splitter window
on one of the tabs. You may collect the latest version of the
class from my Web site:
www.scasoftware.com.

Last updated: January 15, 1999.

More by Author

Must Read