次の方法で共有


CSingleDocTemplate::CSingleDocTemplate

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

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

パラメーター

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

    The string リソースは「\ n 文字で構成されます (「\ 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 種類のエントリとして表示されます。

    これらのリソースの種類に関する詳細については、[文字列エディタ]を参照してください。

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

  • pFrameClass
    フレーム ウィンドウの CRuntimeClass のオブジェクトへのポインターを示します。 このクラスは CFrameWndです-メイン フレーム ウィンドウの既定の動作が必要な場合は、派生クラスかは自体 CFrameWnd です。

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

解説

動的に 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);

必要条件

ヘッダー: afxwin.h

参照

関連項目

CSingleDocTemplate クラス

階層図

CDocTemplate::GetDocString

CWinApp::AddDocTemplate

CWinApp::InitInstance

CRuntimeClass 構造体

RUNTIME_CLASS