The CDocument class provides the basic functionality for user-defined document classes. A document represents the unit of data that the user typically opens with the File Open command and saves with the File Save command.
CDocument supports standard operations such as creating a document, loading it, and saving it. The framework manipulates documents using the interface defined by CDocument.
An application can support more than one type of document; for example, an application might support both spreadsheets and text documents. Each type of document has an associated document template; the document template specifies what resources (for example, menu, icon, or accelerator table) are used for that type of document. Each document contains a pointer to its associated CDocTemplate object.
Users interact with a document through the CView object(s) associated with it. A view renders an image of the document in a frame window and interprets user input as operations on the document. A document can have multiple views associated with it. When the user opens a window on a document, the framework creates a view and attaches it to the document. The document template specifies what type of view and frame window are used to display each type of document.
Documents are part of the framework’s standard command routing and consequently receive commands from standard user-interface components (such as the File Save menu item). A document receives commands forwarded by the active view. If the document doesn’t handle a given command, it forwards the command to the document template that manages it.
When a document’s data is modified, each of its views must reflect those modifications. CDocument provides the UpdateAllViews member function for you to notify the views of such changes, so the views can repaint themselves as necessary. The framework also prompts the user to save a modified file before closing it.
To implement documents in a typical application, you must do the following:
CDocument supports sending your document via mail if mail support (MAPI) is present. See the articles MAPI Topics and MAPI Support in MFC in Visual C++ Programmer's Guide.
For more information on CDocument, see Serialization (Object Persistence), Document/View Architecture Topics, and Document/View Creation in Visual C++ Programmer's Guide.
#include <afxwin.h>
Class Members | Base Class | Hierarchy Chart
Samples MFC Sample HELLO | MFCSample MDIBIND | MFC Sample MDIDOCVW | MFC Sample SNAPVW | MFC Sample NPP
See Also CCmdTarget, CView, CDocTemplate