CMultiDocTemplate::CMultiDocTemplate

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

Parameters

nIDResource

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 is not included; however, trailing ‘\n’ characters are not 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:

// MYCALC.RC
STRINGTABLE PRELOAD DISCARDABLE
BEGIN
    IDR_SHEETTYPE "\nSheet\nWorksheet\nWorksheets (*.myc)\n.myc\n MyCalcSheet\nMyCalc Worksheet"
END

Note that the string begins with a ‘\n’ character; this is because the first substring is not used for MDI applications and so is not 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 in the Visual C++ User’s Guide.

pDocClass

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

pFrameClass

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.

pViewClass

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

Remarks

Constructs a CMultiDocTemplate object. 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.

Example

//example for CMultiDocTemplate
BOOL CMyApp::InitInstance()
{
        // ...
        // Establish all of the document types
        // supported by the application

        AddDocTemplate( new CMultiDocTemplate( IDR_SHEETTYPE,
                            RUNTIME_CLASS( CSheetDoc ),
                            RUNTIME_CLASS( CMDIChildWnd ),
                            RUNTIME_CLASS( CSheetView ) ) );

        AddDocTemplate( new CMultiDocTemplate( IDR_NOTETYPE,
                            RUNTIME_CLASS( CNoteDoc ),
                            RUNTIME_CLASS( CMDIChildWnd ),
                            RUNTIME_CLASS( CNoteView ) ) );
        // ...
}

Here is a second example.

BOOL CYourApp::InitInstance()
{
   // Normally, an application creates a document 
   // template and registers it with MFC as a part
   // of its initialization.

   // IDR_SAMPLERESOURCE 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.

   CMultiDocTemplate* pDocTemplate;
   pDocTemplate = new CMultiDocTemplate(
      IDR_SAMPLERESOURCE,
      RUNTIME_CLASS(CYourDoc),
      RUNTIME_CLASS(CChildFrame),
      RUNTIME_CLASS(CYourViewClass));

   // 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.

   AddDocTemplate(pDocTemplate);

   // You might have other initialization code ...
   // ...

   return TRUE;
}

CMultiDocTemplate OverviewClass MembersHierarchy Chart

See Also   CDocTemplate::GetDocString, CWinApp::AddDocTemplate, CWinApp::InitInstance, CRuntimeClass