Dynamic Splitter Window MDI and Opening Different Types of Document

 

This article shows how to create a dynamic splitter window. This application creates a splitter window with two views, a graphicsview and a textview.  At times we may want to see the top area of the drawing as well as the bottom area without being required to scroll the view. To achieve this we can spilt the graphics view horizontally, into 2 panes. In one pane we can show the top area of the drawing region and in the another, the bottom area. This does not mean that we are restricted to seeing only the top or the bottom area in the two panes. We can scroll both the panes and get the desired portion of the drawing area into the view.
Note that the static splitter window has been created by calling CSplitterWnd::CreateStatic( ), whereas, the dynamic splitter window has been created using CSplitterWnd::Create( ).
The first parameter passed to CSplitterWnd::Create( ) identifies the splitter window’s parent. In our case since the static splitter window is the parent of dynamic splitter window, we have passed the address of the static splitter window object as the first parameter. The second and third parameters specify the numbers of rows and columns that the window should be split into. The fourth parameter specifies each pane’s minimum width and height in pixels. The framework uses these values to determine when panes should be created and destroyed as the splitter bars are moved. CSize values equal to (1,1) specify that panes can be as small as 1 pixel wide and 1 pixel tall. The fifth parameter is a pointer to the CCreateContext structure provided by the framework. You would soon see its relevance. The sixth and seventh optional parameters specify the splitter window’s style and its child window’s id. The seventh parameter is by default AFX_IDW_PANE_FIRST. This id enables a frame window to identify the splitter window associated with it. This id also enables the framework to decide which of the two panes of the static splitter window we want to split. In our case since we wanted the left pane to split we could rely on the default id. Had we wanted to split the right pane then we would have been required to obtain the id of the pane by calling CSplitterWnd::IdFromRowCol( ).
Apart from the way of creation, the static and dynamic splitter windows also differ in the method used to attach views to them. For example, we have specifically attached the text view to the right pane of the static splitter window through a call to CSplitterWnd::CreateView( ). As against this, the view to be attached to the two panes of the dynamic splitter window are specified while creating the CSingleDocTemplate object in myapp::InitInstance( ).