Edit

Share via


Initializing Documents and Views

Documents are created in two different ways, so your document class must support both ways. First, the user can create a new, empty document with the File New command. In that case, initialize the document in your override of the OnNewDocument member function of class CDocument. Second, the user can use the Open command on the File menu to create a new document whose contents are read from a file. In that case, initialize the document in your override of the OnOpenDocument member function of class CDocument. If both initializations are the same, you can call a common member function from both overrides, or OnOpenDocument can call OnNewDocument to initialize a clean document and then finish the open operation.

Views are created after their documents are created. The best time to initialize a view is after the framework has finished creating the document, frame window, and view. You can initialize your view by overriding the OnInitialUpdate member function of CView. If you need to reinitialize or adjust anything each time the document changes, you can override OnUpdate.

See also

Initializing and Cleaning Up Documents and Views