CSingleDocTemplate クラス

SDI (シングル ドキュメント インターフェイス) を実装するドキュメント テンプレートを定義します。

構文

class CSingleDocTemplate : public CDocTemplate

メンバー

パブリック コンストラクター

名前 説明
CSingleDocTemplate::CSingleDocTemplate CSingleDocTemplate オブジェクトを構築します。

解説

SDI アプリケーションでは、メイン フレーム ウィンドウを使用してドキュメントを表示します。一度に開くことができるドキュメントは 1 つだけです。

ドキュメント テンプレートは、次の 3 種類のクラス間のリレーションシップを定義します。

  • 派生元の CDocumentドキュメント クラス。

  • ビュー クラス。上記のドキュメント クラスのデータを表示します。 このクラスは、、、CScrollViewCFormView、または CEditView.CView (直接使用 CEditView することもできます)。

  • ビューを含むフレーム ウィンドウ クラス。 SDI ドキュメント テンプレートの場合は、このクラスをCFrameWnd派生させることができます。メイン フレーム ウィンドウの動作をカスタマイズする必要がない場合は、独自のクラスを派生させずに直接使用CFrameWndできます。

通常、SDI アプリケーションは 1 種類のドキュメントをサポートするため、オブジェクトは 1 つだけ CSingleDocTemplate です。 一度に開くことができるドキュメントは 1 つだけです。

コンストラクター以外のメンバー関数 CSingleDocTemplate を呼び出す必要はありません。 フレームワークは内部的にオブジェクトを処理 CSingleDocTemplate します。

使用CSingleDocTemplateの詳細については、「ドキュメント テンプレート」および「ドキュメント/ビュー作成プロセス」を参照してください

継承階層

CObject

CCmdTarget

Cdoctemplate

CSingleDocTemplate

必要条件

ヘッダー: afxwin.h

CSingleDocTemplate::CSingleDocTemplate

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

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

パラメーター

nIDResource
ドキュメントの種類で使用されるリソースの ID を指定します。 これには、メニュー、アイコン、アクセラレータ テーブル、および文字列リソースが含まれる場合があります。

文字列リソースは、'\n' 文字で区切られた最大 7 個の部分文字列で構成されます (部分文字列が含まれていない場合は、プレースホルダーとして '\n' 文字が必要です。ただし、末尾の '\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表すために定義する -derived クラスです。

pFrameClass
フレーム ウィンドウ クラスの CRuntimeClass オブジェクトをポイントします。 このクラスはCFrameWnd、-derived クラスにすることもCFrameWnd、メイン フレーム ウィンドウの既定の動作が必要な場合はそれ自体にすることもできます。

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

解説

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

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

関連項目

MFC サンプル DOCKTOOL
CDocTemplate クラス
階層図
CDocTemplate クラス
CDocument クラス
CFrameWnd クラス
CMultiDocTemplate クラス
CView クラス
CWinApp クラス