Delen via


Document Template Creation

When creating a new document in response to a New or Open command from the File menu, the document template also creates a new frame window through which to view the document.

The document-template constructor specifies what types of documents, windows, and views the template will be able to create. This is determined by the arguments you pass to the document-template constructor. The following code illustrates creation of a CMultiDocTemplate for a sample application:

CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_CMyDocTypeTYPE,
   RUNTIME_CLASS(CMyDoc),
   RUNTIME_CLASS(CChildFrame), // custom MDI child frame
   RUNTIME_CLASS(CMyView));
if (!pDocTemplate)
   return FALSE;
AddDocTemplate(pDocTemplate);

The pointer to a new CMultiDocTemplate object is used as an argument to AddDocTemplate. Arguments to the CMultiDocTemplate constructor include the resource ID associated with the document type's menus and accelerators, and three uses of the RUNTIME_CLASS macro. RUNTIME_CLASS returns the CRuntimeClass object for the C++ class named as its argument. The three CRuntimeClass objects passed to the document-template constructor supply the information needed to create new objects of the specified classes during the document creation process. The example shows creation of a document template that creates CScribDoc objects with CScribView objects attached. The views are framed by standard MDI child frame windows.

See Also

Concepts

Document Templates and the Document/View Creation Process

Document/View Creation

Relationships Among MFC Objects

Creating New Documents, Windows, and Views