Multiple Document Types, Views, and Frame Windows

HomeOverviewHow Do ISampleTutorial

The standard relationship among a document, its view, and its frame window is described in Document/View Creation. Many applications support a single document type (but possibly multiple open documents of that type) with a single view on the document and only one frame window per document. But some applications may need to alter one or more of those defaults.

What do you want to know more about?

Multiple Document Types

AppWizard creates a single document class for you. In some cases, though, you may need to support more than one document type. For example, your application may need worksheet and chart documents. Each document type is represented by its own document class and probably by its own view class as well. When the user chooses the File New command, the framework displays a dialog box that lists the supported document types. Then it creates a document of the type that the user chooses. Each document type is managed by its own document-template object.

To create extra document classes, use the Add Class button in the ClassWizard dialog box. Choose CDocument as the Class Type to derive from and supply the requested document information. Then implement the new class's data.

To let the framework know about your extra document class, you must add a second call to AddDocTemplate in your application class's InitInstance override. For more information, see Document Templates.

Multiple Views

Many documents require only a single view, but it is possible to support more than one view of a single document. To help you implement multiple views, a document object keeps a list of its views, provides member functions for adding and removing views, and supplies the UpdateAllViews member function for letting multiple views know when the document's data has changed.

MFC supports three common user interfaces requiring multiple views on the same document. These models are:

The following figure, divided into parts a, b, and c, shows the three user-interface models in the order presented above.

Multiple-View User Interfaces

The framework provides these models by implementing the New Window command and by providing class CSplitterWnd, as discussed in Splitter Windows. You can implement other models using these as your starting point. For sample programs that illustrate different configurations of views, frame windows, and splitters, see MFC Samples under Samples.

For more information about UpdateAllViews, see class CView in the Class Library Reference and Enhancing Views in Tutorials.

Multiple Frame Windows

You can use the New Window command to create a second frame window on the same document. For more information, see the first model in the figure Multiple-View User Interfaces.

Splitter Windows

In a splitter window, the window is, or can be, split into two or more scrollable panes. A splitter control (or "split box") in the window frame next to the scroll bars allows the user to adjust the relative sizes of the panes. Each pane is a view on the same document. In "dynamic" splitters, the views are of the same class, as shown in part b of the figure Multiple-View User Interfaces. In "static" splitters, the views can be of different classes. Splitter windows of both kinds are supported by class CSplitterWnd.

Dynamic splitter windows, with views of the same class, allow the user to split a window into multiple panes at will and then scroll different panes to see different parts of the document. The user can also unsplit the window to remove the additional views. The splitter windows added to the Scribble application in Enhancing Views in Tutorials are an example. That topic describes the technique for creating dynamic splitter windows. A dynamic splitter window is shown in part b of the figure Multiple-View User Interfaces.

Static splitter windows, with views of different classes, start with the window split into multiple panes, each with a different purpose. For example, in the Visual C++ bitmap editor, the image window shows two panes side by side. The left-hand pane displays a life-sized image of the bitmap. The right-hand pane displays a zoomed or magnified image of the same bitmap. The panes are separated by a "splitter bar" that the user can drag to change the relative sizes of the panes. A static splitter window is shown in part c of the figure Multiple-View User Interfaces.

For more information, see class CSplitterWnd in the Class Library Reference and MFC Samples under Samples.