共用方式為


CDocTemplate Class

An abstract base class that defines the basic functionality for document templates.

class CDocTemplate : public CCmdTarget

Members

Protected Constructors

Name

Description

CDocTemplate::CDocTemplate

Constructs a CDocTemplate object.

Public Methods

Name

Description

CDocTemplate::AddDocument

Adds a document to a template.

CDocTemplate::CloseAllDocuments

Closes all documents associated with this template.

CDocTemplate::CreateNewDocument

Creates a new document.

CDocTemplate::CreateNewFrame

Creates a new frame window containing a document and view.

CDocTemplate::CreateOleFrame

Creates an OLE-enabled frame window.

CDocTemplate::CreatePreviewFrame

Creates a child frame used for Rich Preview.

CDocTemplate::GetDocString

Retrieves a string associated with the document type.

CDocTemplate::GetFirstDocPosition

Retrieves the position of the first document associated with this template.

CDocTemplate::GetNextDoc

Retrieves a document and the position of the next one.

CDocTemplate::InitialUpdateFrame

Initializes the frame window, and optionally makes it visible.

CDocTemplate::LoadTemplate

Loads the resources for a given CDocTemplate or derived class.

CDocTemplate::MatchDocType

Determines the degree of confidence in the match between a document type and this template.

CDocTemplate::OpenDocumentFile

Opens a file specified by a pathname.

CDocTemplate::RemoveDocument

Removes a document from a template.

CDocTemplate::SaveAllModified

Saves all documents associated with this template which have been modified.

CDocTemplate::SetContainerInfo

Determines the resources for OLE containers when editing an in-place OLE item.

CDocTemplate::SetDefaultTitle

Displays the default title in the document window's title bar.

CDocTemplate::SetPreviewInfo

Setups out of process preview handler.

CDocTemplate::SetServerInfo

Determines the resources and classes when the server document is embedded or edited in-place.

Remarks

You usually create one or more document templates in the implementation of your application's InitInstance function. A document template defines the relationships among three types of classes:

  • A document class, which you derive from CDocument.

  • A view class, which displays data from the document class listed above. You can derive this class from CView, CScrollView, CFormView, or CEditView. (You can also use CEditView directly.)

  • A frame window class, which contains the view. For a single document interface (SDI) application, you derive this class from CFrameWnd. For a multiple document interface (MDI) application, you derive this class from CMDIChildWnd. If you don't need to customize the behavior of the frame window, you can use CFrameWnd or CMDIChildWnd directly without deriving your own class.

Your application has one document template for each type of document that it supports. For example, if your application supports both spreadsheets and text documents, the application has two document template objects. Each document template is responsible for creating and managing all the documents of its type.

The document template stores pointers to the CRuntimeClass objects for the document, view, and frame window classes. These CRuntimeClass objects are specified when constructing a document template.

The document template contains the ID of the resources used with the document type (such as menu, icon, or accelerator table resources). The document template also has strings containing additional information about its document type. These include the name of the document type (for example, "Worksheet") and the file extension (for example, ".xls"). Optionally, it can contain other strings used by the application's user interface, the Windows File Manager, and Object Linking and Embedding (OLE) support.

If your application is an OLE container and/or server, the document template also defines the ID of the menu used during in-place activation. If your application is an OLE server, the document template defines the ID of the toolbar and menu used during in-place activation. You specify these additional OLE resources by calling SetContainerInfo and SetServerInfo.

Because CDocTemplate is an abstract class, you cannot use the class directly. A typical application uses one of the two CDocTemplate-derived classes provided by the Microsoft Foundation Class Library: CSingleDocTemplate, which implements SDI, and CMultiDocTemplate, which implements MDI. See those classes for more information on using document templates.

If your application requires a user-interface paradigm that is fundamentally different from SDI or MDI, you can derive your own class from CDocTemplate.

For more information on CDocTemplate, see Document Templates and the Document/View Creation Process.

Inheritance Hierarchy

CObject

CCmdTarget

CDocTemplate

Requirements

Header: afxwin.h

See Also

Reference

CCmdTarget Class

Hierarchy Chart

CSingleDocTemplate Class

CMultiDocTemplate Class

CDocument Class

CView Class

CScrollView Class

CEditView Class

CFormView Class

CFrameWnd Class

CMDIChildWnd Class