Share via

CMultiDocTemplate Class

Defines a document template that implements the multiple document interface (MDI).


class CMultiDocTemplate : public CDocTemplate


The member functions for this class are virtual. See CDocTemplate and CCmdTarget for documentation.

Public Constructors

Name Description
CMultiDocTemplate::CMultiDocTemplate Constructs a CMultiDocTemplate object.


An MDI application uses the main frame window as a workspace in which the user can open zero or more document frame windows, each of which displays a document. For a more detailed description of the MDI, see Windows Interface Guidelines for Software Design.

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 an MDI document template, you can derive this class from CMDIChildWnd, or, if you don't need to customize the behavior of the document frame windows, you can use CMDIChildWnd directly without deriving your own class.

An MDI application can support more than one type of document, and documents of different types can be open at the same time. Your application has one document template for each document type that it supports. For example, if your MDI application supports both spreadsheets and text documents, the application has two CMultiDocTemplate objects.

The application uses the document template(s) when the user creates a new document. If the application supports more than one type of document, then the framework gets the names of the supported document types from the document templates and displays them in a list in the File New dialog box. Once the user has selected a document type, the application creates a document class object, a frame window object, and a view object and attaches them to each other.

You don't need to call any member functions of CMultiDocTemplate except the constructor. The framework handles CMultiDocTemplate objects internally.

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

Inheritance Hierarchy






Header: afxwin.h


Constructs a CMultiDocTemplate object.

    UINT nIDResource,
    CRuntimeClass* pDocClass,
    CRuntimeClass* pFrameClass,
    CRuntimeClass* pViewClass);


Specifies the ID of the resources used with the document type. This may include menu, icon, accelerator table, and string resources.

The string resource consists of up to seven substrings separated by the '\n' character (the '\n' character is needed as a place holder if a substring isn't included; however, trailing '\n' characters aren't necessary); these substrings describe the document type. For information on the substrings, see CDocTemplate::GetDocString. This string resource is found in the application's resource file. For example:

  IDR_SHEETTYPE "\nSheet\nWorksheet\nWorksheets (*.myc)\n.myc\n MyCalcSheet\nMyCalc Worksheet"

The string begins with a '\n' character because the first substring isn't used for MDI applications and so isn't included. You can edit this string using the string editor; the entire string appears as a single entry in the String Editor, not as seven separate entries.

For more information about these resource types, see Resource Editors.

Points to the CRuntimeClass object of the document class. This class is a CDocument-derived class you define to represent your documents.

Points to the CRuntimeClass object of the frame-window class. This class can be a CMDIChildWnd-derived class, or it can be CMDIChildWnd itself if you want default behavior for your document frame windows.

Points to the CRuntimeClass object of the view class. This class is a CView-derived class you define to display your documents.


Dynamically allocate one CMultiDocTemplate object for each document type that your application supports and pass each one to CWinApp::AddDocTemplate from the InitInstance member function of your application class.


// Code fragment from CMyApp::InitInstance

// Establish all of the document types
// supported by the application

AddDocTemplate(new CMultiDocTemplate(IDR_BRUSHDOCTYPE,

AddDocTemplate(new CMultiDocTemplate(IDR_DCDOCTYPE,

Here is a second example.

// Code fragment taken from CMyApp::InitInstance

// Normally, an application creates a document 
// template and registers it with MFC as a part
// of its initialization.

// IDR_EXAMPLEDOCTYPE is a resource ID string; see
// the CDocTemplate class overview documentation
// for more information on its format.

// The next three parameters use the RUNTIME_CLASS()
// macro to get runtime type information for the doc,
// frame, and view classes that will be associated
// by the template.

pDocTemplate = new CMultiDocTemplate(IDR_EXAMPLEDOCTYPE,
if (!pDocTemplate)
return FALSE;

// After the following call, MFC is aware of the doc
// template and will free it when the application is
// shut down. The doc templates known to MFC will
// automatically be used when CWinApp:OnFileOpen()
// or CWinApp::OnFileNew() are called.


See also

CDocTemplate Class
Hierarchy Chart
CDocTemplate Class
CSingleDocTemplate Class
CWinApp Class