共用方式為


CMultiDocTemplate 類別

定義實作多重文件介面 (MDI) 的文件範本。

語法

class CMultiDocTemplate : public CDocTemplate

成員

此類別的成員函式是虛擬的。 如需檔,請參閱 CDocTemplate CCmdTarget

公用建構函式

名稱 描述
CMultiDocTemplate::CMultiDocTemplate 建構 CMultiDocTemplate 物件。

備註

MDI 應用程式會使用主框架視窗做為工作區,讓使用者可以開啟零個或多個檔框架視窗,其中每個視窗都會顯示檔。 如需 MDI 的更詳細描述,請參閱 軟體設計的 Windows 介面指導方針。

檔範本會定義三種類別之間的關聯性:

  • 檔類別,衍生自 CDocument

  • 檢視類別,顯示上面所列檔類別的資料。 您可以從 CView 、、 CScrollViewCFormViewCEditView 衍生這個類別 。 (您也可以直接使用 CEditView

  • 包含檢視的框架視窗類別。 針對 MDI 檔範本,您可以從 衍生此類別 CMDIChildWnd ,或者,如果您不需要自訂檔框架視窗的行為,則可以直接使用 CMDIChildWnd 而不衍生您自己的類別。

MDI 應用程式可以支援一種以上的檔,而且可以同時開啟不同類型的檔。 您的應用程式針對它支援的每個檔案類型都有一個檔範本。 例如,如果您的 MDI 應用程式同時支援試算表和文字檔,應用程式就會有兩個 CMultiDocTemplate 物件。

當使用者建立新檔時,應用程式會使用檔範本。 如果應用程式支援多個檔案類型,則架構會從檔範本取得支援的檔案類型名稱,並在 [檔案新增] 對話方塊中的清單中顯示它們。 使用者選取檔案類型之後,應用程式會建立檔類別物件、框架視窗物件和檢視物件,並將它們附加至彼此。

除了建構函式之外,您不需要呼叫 的任何成員函 CMultiDocTemplate 式。 架構會在內部處理 CMultiDocTemplate 物件。

如需 的詳細資訊 CMultiDocTemplate ,請參閱 檔範本和檔/檢視建立程式

繼承階層架構

CObject

CCmdTarget

CDocTemplate

CMultiDocTemplate

需求

標題: afxwin.h

CMultiDocTemplate::CMultiDocTemplate

建構 CMultiDocTemplate 物件。

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

參數

nIDResource
指定搭配檔案類型使用之資源的識別碼。 這可能包括功能表、圖示、快速鍵資料表和字串資源。

字串資源是由以 '\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' 字元開頭,因為第一個子字串不會用於 MDI 應用程式,因此不包含。 您可以使用字串編輯器來編輯此字串;整個字串會顯示為字串編輯器中的單一專案,而不是七個不同的專案。

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

pDocClass
CRuntimeClass指向檔類別的物件。 這個類別是您 CDocument 定義來代表檔的衍生類別。

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

pViewClass
指向 CRuntimeClass 檢視類別的物件。 這個類別是 CView 用來顯示檔的衍生類別。

備註

針對應用程式支援的每個檔案類型動態配置一個 CMultiDocTemplate 物件,並將每個物件從應用程式類別的成員函式傳遞至 CWinApp::AddDocTemplateInitInstance

範例

// 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);

另請參閱

CDocTemplate 類別
階層架構圖表
CDocTemplate 類別
CSingleDocTemplate 類別
CWinApp 類別