MFC - Splitter window example

Visual C++ Tutorials Step by step learnings

 
A splitter can be divided into two or more panes horizontally as well as vertically. Each pane size can be changed dynamically using movable splitter bars. Each pane can contain one view of the document’s data. The views are children of the splitter window, whereas, the splitter window is a child of a frame window. In this article we have created a static splitter window with two panes, one displays text and another graphics.
    Explanation:
    The MDI architecture not only permits us to open more than one document of a particular type, but it also allows us to open different types of documents in an application.  To help you understand this facility we have put together an application, which has the following provisions:

    (a) There are two types of documents: one, which stores information about the lines and rectangles drawn interactively, and another, which stores information about the circles drawn interactively. Here onwards we would call these documents as landr and circle documents respectively.
    (b) When the landr document is opened, two views of the document are displayed in splitter windows. We have first created a static splitter window containing two panes. The right pane contains the text view showing the line count, the rectangle count, the current shape, line color, line thickness and brush color. The left pane houses a dynamic splitter window containing two panes. Each of these panes show the graphics view of lines and rectangles.
    When the circle document is opened, using the document data, circles are built in a view window. Unlike the view of landr document mentioned above, this view does not contain any splitter window.
    (c) Whenever we open a landr or a circle document the window housing its view(s) would show an appropriate icon. Note that these icons are different than the icon of the frame window.
    (d) Whenever we attempt to open a new document using ‘File | New’, a dialog box is popped up asking the user to select the type of document to open. A similar dialog is also popped up when we start the application with an empty document. This dialog is shown below:

        figure mdisplitter1.gif
    Figure 1.  Opening a document in an MDI application.

    The names of the types of documents in the above dialog are obtained through the third sub-string of the document string. The document strings that we have created for the two types of documents are as under:

    IDR_CHILDFRAME1        \nNoname\nLine Rectangle Document
                            \nLineRect Files(*.lnr)\n.lnr
                            \nShapes.Document\nOur Shapes Document


    IDR_CHILDFRAME2        \nNoname\nCircle Document
                            \nCircle Files(*.cir) \n.cir\nShapes.Document
                            \nOur Shapes Document

    Note that the fourth and the fifth sub-string in the above two document strings represent two different types of documents that the application supports.

    Figure 2  shows two documents created using this program. One shows line and rectangle drawn using the program and another shows the circles drawn using it.

        Figure mdisplitter2.gif
    Figure 2.  Mutiple types of documents opened in an MDI app.