Condividi tramite


Creating New Documents, Windows, and Views

The following figures give an overview of the creation process for documents, views, and frame windows. Other articles that focus on the participating objects provide further details.

Upon completion of this process, the cooperating objects exist and store pointers to each other. The following figures show the sequence in which objects are created. You can follow the sequence from figure to figure.

Sequence in Creating a Document

Creating Document Sequence

Sequence in Creating a Frame Window

Frame Window Creation Sequence

Sequence in Creating a View

View Creation Sequence

For information about how the framework initializes the new document, view, and frame-window objects, see classes CDocument, CView, CFrameWnd, CMDIFrameWnd, and CMDIChildWnd in the MFC Library Reference. Also see Technical Note 22, which explains the creation and initialization processes further under its discussion of the framework's standard commands for the New and Open items on the File menu.

Initializing Your Own Additions to These Classes

The preceding figures also suggest the points at which you can override member functions to initialize your application's objects. An override of OnInitialUpdate in your view class is the best place to initialize the view. The OnInitialUpdate call occurs immediately after the frame window is created and the view within the frame window is attached to its document. For example, if your view is a scroll view (derived from CScrollView rather than CView), you should set the view size based on the document size in your OnInitialUpdate override. (This process is described in the description of class CScrollView.) You can override the CDocument member functions OnNewDocument and OnOpenDocument to provide application-specific initialization of the document. Typically, you must override both since a document can be created in two ways.

In most cases, your override should call the base class version. For more information, see the named member functions of classes CDocument, CView, CFrameWnd, and CWinApp in the MFC Library Reference.

See Also

Concepts

Document Templates and the Document/View Creation Process

Document Template Creation

Document/View Creation

Relationships Among MFC Objects