CSingleDocTemplate::CSingleDocTemplate

更新 : 2007 年 11 月

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

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

パラメータ

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

    文字列リソースは、'\n' 文字で区切った 7 つ以下の部分文字列で構成されます。'\n' 文字は部分文字列がなくても位置決めのために必要ですが、文字列の最後になるときは必要ありません。これらの部分文字列がドキュメント型を表します。部分文字列の詳細については、「CDocTemplate::GetDocString」を参照してください。この文字列リソースは、アプリケーションのリソース ファイルに記述されます。次に例を示します。

    // MYCALC.RC

    STRINGTABLE PRELOAD DISCARDABLE

    BEGIN

    IDR_MAINFRAME "MyCalc Windows Application\nSheet\nWorksheet\n Worksheets (*.myc)\n.myc\nMyCalcSheet\n MyCalc Worksheet"

    END

    この文字列はストリング エディタを使って編集できます。ストリング エディタでは、7 つの部分に分けられずに、1 つの文字列として表示されます。

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

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

  • pFrameClass
    フレーム ウィンドウ クラスの CRuntimeClass オブジェクトへのポインタ。このクラスとして、CFrameWnd クラスの派生クラス、またはメイン フレーム ウィンドウの既定の動作でよければ、CFrameWnd クラス自身を使用できます。

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

解説

アプリケーション クラスの InitInstance メンバ関数の中で、CWinApp::AddDocTemplate に渡す CSingleDocTemplate オブジェクトを動的に割り当てます。

使用例

// The following code fragment is from CMyWinApp::InitInstance.
// CMyWinApp is derived from CWinApp.

// Establish the document type
// supported by the application
AddDocTemplate(new CSingleDocTemplate(IDR_MAINFRAME,
   RUNTIME_CLASS(CMyDoc),
   RUNTIME_CLASS(CMainFrame),       // main SDI frame window
   RUNTIME_CLASS(CMyView)));
// The following code fragment is from CMyWinApp::InitInstance.
// CMyWinApp is derived from CWinApp.

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

CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,
   RUNTIME_CLASS(CMyDoc),
   RUNTIME_CLASS(CMainFrame),       // main SDI frame window
   RUNTIME_CLASS(CMyView));
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

参照

参照

CSingleDocTemplate クラス

階層図

CDocTemplate::GetDocString

CWinApp::AddDocTemplate

CWinApp::InitInstance

CRuntimeClass 構造体

RUNTIME_CLASS

その他の技術情報

CSingleDocTemplate のメンバ