Creating Document Frame Windows

Document/View Creation shows how the CDocTemplate object orchestrates creating the frame window, document, and view and connecting them all together. Three CRuntimeClass arguments to the CDocTemplate constructor specify the frame window, document, and view classes that the document template creates dynamically in response to user commands such as the New command on the File menu or the New Window command on an MDI Window menu. The document template stores this information for later use when it creates a frame window for a view and document.

For the RUNTIME_CLASS mechanism to work correctly, your derived frame-window classes must be declared with the DECLARE_DYNCREATE macro. This is because the framework needs to create document frame windows using the dynamic construction mechanism of class CObject.

When the user chooses a command that creates a document, the framework calls upon the document template to create the document object, its view, and the frame window that will display the view. When it creates the document frame window, the document template creates an object of the appropriate class — a class derived from CFrameWnd for an SDI application or from CMDIChildWnd for an MDI application. The framework then calls the frame-window object's LoadFrame member function to get creation information from resources and to create the Windows window. The framework attaches the window handle to the frame-window object. Then it creates the view as a child window of the document frame window.

Use caution in deciding when to initialize your CWnd-derived object.

What do you want to know more about

See also

Using Frame Windows