CSingleDocTemplate クラス
SDI (シングル ドキュメント インターフェイス) を実装するドキュメント テンプレートを定義します。
構文
class CSingleDocTemplate : public CDocTemplate
メンバー
パブリック コンストラクター
名前 | 説明 |
---|---|
CSingleDocTemplate::CSingleDocTemplate | CSingleDocTemplate オブジェクトを構築します。 |
注釈
SDI アプリケーションは、メイン フレーム ウィンドウを使用してドキュメントを表示します。一度に開くことができるドキュメントは 1 つのみです。
ドキュメント テンプレートは、次の 3 種類のクラス間のリレーションシップを定義します。
から派生したドキュメント クラス
CDocument
。上記のドキュメント クラスのデータを表示するビュー クラス。 このクラスは、、、、または
CView
CScrollView
からCFormView
派生できますCEditView
。 (直接使用CEditView
することもできます)。ビューを含むフレーム ウィンドウ クラス。 SDI ドキュメント テンプレート
CFrameWnd
CFrameWnd
の場合は、 からこのクラスを派生できます。メイン フレーム ウィンドウの動作をカスタマイズする必要がない場合は、独自のクラスを派生せずに直接使用できます。
SDI アプリケーションは通常、1 種類のドキュメントをサポートします。そのため、オブジェクトは 1 つ CSingleDocTemplate
のみです。 一度に開くことができるドキュメントは 1 つのみです。
コンストラクターを除き、 のメンバー関数を呼び CSingleDocTemplate
出す必要はありません。 フレームワークは、オブジェクトを CSingleDocTemplate
内部的に処理します。
の使用の詳細については、「ドキュメント CSingleDocTemplate
テンプレート 」および「ドキュメント/ビュー作成プロセス」を参照してください。
継承階層
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
を表すとして定義する派生クラスです。
pFrameClass
フレーム ウィンドウ クラス CRuntimeClass
の オブジェクトをポイントします。 このクラスは、派生 CFrameWnd
クラスに CFrameWnd
することもできますし、メイン フレーム ウィンドウの既定の動作が必要な場合はそれ自体にすることもできます。
pViewClass
ビュー クラスの CRuntimeClass
オブジェクトをポイントします。 このクラスは、 CView
ドキュメントを表示するために定義する派生クラスです。
注釈
オブジェクトを動的に割 CSingleDocTemplate
り当て、アプリケーション クラス CWinApp::AddDocTemplate
のメンバー InitInstance
関数から に渡します。
例
// 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 クラス