次の方法で共有


CMultiDocTemplate::CMultiDocTemplate

更新 : 2007 年 11 月

CMultiDocTemplate オブジェクトを構築します。

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

パラメータ

  • nIDResource
    ドキュメント型で使用するリソースの ID を指定します。メニュー、アイコン、アクセラレータ テーブル、文字列リソースなどを指定できます。

    文字列リソースは、'\n' 文字で区切られた最大 7 つの部分文字列で構成されます (部分文字列がない場合でも、プレースホルダとして '\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 アプリケーションでは使用されていないので、取り込まれないからです。この文字列はストリング エディタを使って編集できます。ストリング エディタでは、7 つの部分に分けられずに、1 つの文字列として表示されます。

    リソース型の詳細については、「リソース エディタ」を参照してください。

  • pDocClass
    ドキュメント クラスの CRuntimeClass オブジェクトへのポインタ。このクラスは、ドキュメントを表すために定義した CDocument の派生クラスです。

  • pFrameClass
    フレーム ウィンドウ クラスの CRuntimeClass オブジェクトへのポインタ。このクラスは、CMDIChildWnd の派生クラス、または既定の動作の場合、CMDIChildWnd 自体が使用できます。

  • pViewClass
    ビュー クラスの CRuntimeClass オブジェクトへのポインタ。このクラスは、ドキュメントを表示するために定義した CView の派生クラスです。

解説

アプリケーション クラスの InitInstance メンバ関数の中で、アプリケーションがサポートするドキュメント型ごとに 1 つずつ 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)));

2 番目の例は次のとおりです。

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

必要条件

ヘッダー : afxwin.h

参照

参照

CMultiDocTemplate クラス

階層図

CDocTemplate::GetDocString

CWinApp::AddDocTemplate

CWinApp::InitInstance

CRuntimeClass 構造体

その他の技術情報

CMultiDocTemplate のメンバ