Export (0) Print
Expand All
Expand Minimize

CDocument Class

Provides the basic functionality for user-defined document classes.

class CDocument : public CCmdTarget

Name

Description

CDocument::CDocument

Constructs a CDocument object.

Name

Description

CDocument::AddView

Attaches a view to the document.

CDocument::BeginReadChunks

Initializes chunk reading.

CDocument::CanCloseFrame

Advanced overridable; called before closing a frame window viewing this document.

CDocument::ClearChunkList

Clears the chunk list.

CDocument::ClearPathName

Clears the path of the document object.

CDocument::DeleteContents

Called to perform cleanup of the document.

CDocument::FindChunk

Looks for a chunk with specified GUID.

CDocument::GetAdapter

Returns a pointer to object implementing IDocument interface.

CDocument::GetDocTemplate

Returns a pointer to the document template that describes the type of the document.

CDocument::GetFile

Returns a pointer to the desired CFile object.

CDocument::GetFirstViewPosition

Returns the position of the first in the list of views; used to begin iteration.

CDocument::GetNextView

Iterates through the list of views associated with the document.

CDocument::GetPathName

Returns the path of the document's data file.

CDocument::GetThumbnail

Called to create a bitmap to be used by thumbnail provider to display thumbnail.

CDocument::GetTitle

Returns the document's title.

CDocument::InitializeSearchContent

Called to initialize search content for Search Handler.

CDocument::IsModified

Indicates whether the document has been modified since it was last saved.

CDocument::IsSearchAndOrganizeHandler

Tells whether this instance of CDocument object was created for Search & Organize handler.

CDocument::LoadDocumentFromStream

Called to load document data from stream.

CDocument::OnBeforeRichPreviewFontChanged

Called before Rich Preview font is changed.

CDocument::OnChangedViewList

Called after a view is added to or removed from the document.

CDocument::OnCloseDocument

Called to close the document.

CDocument::OnCreatePreviewFrame

Called by the framework when it needs to create a preview frame for Rich Preview.

CDocument::OnDocumentEvent

Called by the framework in response to a document event.

CDocument::OnDrawThumbnail

Override this method in a derived class to draw content of thumbnail.

CDocument::OnLoadDocumentFromStream

Called by the framework when it needs to load the document data from stream.

CDocument::OnNewDocument

Called to create a new document.

CDocument::OnOpenDocument

Called to open an existing document.

CDocument::OnPreviewHandlerQueryFocus

Directs the preview handler to return the HWND from calling the GetFocus Function.

CDocument::OnPreviewHandlerTranslateAccelerator

Directs the preview handler to handle a keystroke passed up from the message pump of the process in which the preview handler is running.

CDocument::OnRichPreviewBackColorChanged

Called when Rich Preview background color has changed.

CDocument::OnRichPreviewFontChanged

Called when Rich Preview font has changed.

CDocument::OnRichPreviewSiteChanged

Called when Rich Preview site has changed.

CDocument::OnRichPreviewTextColorChanged

Called when Rich Preview text color has changed.

CDocument::OnSaveDocument

Called to save the document to disk.

CDocument::OnUnloadHandler

Called by the framework when the preview handler is being unloaded.

CDocument::PreCloseFrame

Called before the frame window is closed.

CDocument::ReadNextChunkValue

Reads next chunk value.

CDocument::ReleaseFile

Releases a file to make it available for use by other applications.

CDocument::RemoveChunk

Removes a chunk with specified GUID.

CDocument::RemoveView

Detaches a view from the document.

CDocument::ReportSaveLoadException

Advanced overridable; called when an open or save operation cannot be completed because of an exception.

CDocument::SaveModified

Advanced overridable; called to ask the user whether the document should be saved.

CDocument::SetChunkValue

Sets a chunk value.

CDocument::SetModifiedFlag

Sets a flag indicating that you have modified the document since it was last saved.

CDocument::SetPathName

Sets the path of the data file used by the document.

CDocument::SetTitle

Sets the document's title.

CDocument::UpdateAllViews

Notifies all views that document has been modified.

Name

Description

CDocument::OnFileSendMail

Sends a mail message with the document attached.

CDocument::OnUpdateFileSendMail

Enables the Send Mail command if mail support is present.

Name

Description

CDocument::m_bGetThumbnailMode

Specifies that CDocument object was created by dllhost for thumbnails. Should be checked in CView::OnDraw.

CDocument::m_bPreviewHandlerMode

Specifies that CDocument object was created by prevhost for Rich Preview. Should be checked in CView::OnDraw.

CDocument::m_bSearchMode

Specifies that CDocument object was created by indexer or other search application.

CDocument::m_clrRichPreviewBackColor

Specifies background color of Rich Preview window. This color is set by host.

CDocument::m_clrRichPreviewTextColor

Specifies foreground color of Rich Preview window. This color is set by host.

CDocument::m_lfRichPreviewFont

Specifies text font for Rich Preview window. This font information is set by host.

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:

  • Derive a class from CDocument for each type of document.

  • Add member variables to store each document's data.

  • Implement member functions for reading and modifying the document's data. The document's views are the most important users of these member functions.

  • Override the CObject::Serialize member function in your document class to write and read the document's data to and from disk.

CDocument supports sending your document via mail if mail support (MAPI) is present. See the articles MAPI and MAPI Support in MFC.

For more information on CDocument, see Serialization, Document/View Architecture Topics, and Document/View Creation.

Header: afxwin.h

Show:
© 2014 Microsoft