Share via


CMultiDocTemplate::CMultiDocTemplate

建構 CMultiDocTemplate 物件。

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

參數

  • nIDResource
    指定資源的 ID 搭配文件類型。 這可能包括功能表、圖示、快速鍵對應表和字串資源。

    資源字串包含" \ n "字元所分隔的子字串七個字元 (" \ n 字元必須做為預留位置,如果子字串不包含在內,不過,結尾的" \ n 字元不是必要的),這些子字串描述文件類型。 如需子字串的詳細資訊,請參閱 CDocTemplate::GetDocString。 這個字串資源在應用程式的資源檔中。 例如:

    // MYCALC.RC

    STRINGTABLE PRELOAD DISCARDABLE

    BEGIN

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

    END

    請注意字串開頭為「\n' character; this is because the first substring is not used for MDI 應用程式,因此不是包含的。 使用字串編輯器,您可以編輯這個字串相同,整個字串會顯示為字串編輯器中的單一項目,而在中則不同型別。

    如需這些資源類型的詳細資訊,請參閱 資源編輯器

  • pDocClass
    in 文件的 CRuntimeClass 指向類別的物件。 這個類別是 CDocument-您定義用以代表文件的衍生類別。

  • pFrameClass
    是框架視窗的 CRuntimeClass 指向類別的物件。 這個類別可 CMDIChildWnd衍生類別也可以是 CMDIChildWnd ,或者如果您想要文件框架視窗的預設行為。

  • pViewClass
    對檢視的 CRuntimeClass 指向類別的物件。 這個類別是 CView-您定義顯示您的文件中的衍生類別。

備註

從應用程式類別的 InitInstance 成員函式動態配置每個資料型別的 CMultiDocTemplate 物件讓應用程式支援並傳遞每一個都 CWinApp::AddDocTemplate

範例

// Code fragment from CMyApp::InitInstance

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

AddDocTemplate(new CMultiDocTemplate(IDR_BRUSHDOCTYPE,
   RUNTIME_CLASS(CBrushDoc),
   RUNTIME_CLASS(CChildFrame),
   RUNTIME_CLASS(CBrushView)));

AddDocTemplate(new CMultiDocTemplate(IDR_DCDOCTYPE,
   RUNTIME_CLASS(CDCDoc),
   RUNTIME_CLASS(CChildFrame),
   RUNTIME_CLASS(CDCView)));

這第二個範例。

// 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,
   RUNTIME_CLASS(CExampleDoc),
   RUNTIME_CLASS(CChildFrame),
   RUNTIME_CLASS(CExampleView));
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.

AddDocTemplate(pDocTemplate);

需求

Header: afxwin.h

請參閱

參考

CMultiDocTemplate 類別

階層架構圖

CDocTemplate::GetDocString

CWinApp::AddDocTemplate

CWinApp::InitInstance

CRuntimeClass 結構