Different Views In Dynamic Splitter

Same view in the dynamic splitter is very restrictive. There is no point in creating same type of views. Here is a way to create different view, each time you split the window.

In class definition of CSplitterWnd, there is a protected member m_pDynamicViewClass of the type CRunTimeClass *. This member is initialized in the Create call of the splitter window. Next time when a view is created, new view is constructed using m_pDynamicViewClass member. To get a different view, you will just have to change the member m_pDynamicViewClass to the required new view. Since this member is a protected member, to change it I have derived my class ‘CDynSplitter’ from class CSplitterWnd. I have just added a function to change member m_pDynamicViewClass.


class CDynSplitter : public CSplitterWnd
{
public:

CDynSplitter() ;
virtual ~CDynSplitter() ;

void ChangeViewClass( CRuntimeClass *pNewView )
{
m_pDynamicViewClass = pNewView ;
}

// Other overridden functions …

};

You call this function and pass a CRuntimeClass pointer of new view. I have given a sample application, in which there are two views, one is a form view and another is a list view. In that I am just calling the same function so that the new view will be created of different type. I have also overridden a function DeleteView(int row, int col); to change m_pDynamicViewClass pointer to the view to be deleted, so that next time the deleted view will be created again.

Download demo project – 164 KB

Download source – 38 KB

Date Last Updated: February 8, 1999

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read