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