CSingleDocTemplate::CSingleDocTemplate

构造 CSingleDocTemplate 对象。

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

参数

  • nIDResource
    指定资源的ID用于文件类型。 这可能包括菜单、图标、快捷键对应表和字符串资源。

    字符串资源包括“\ n字符分隔的七子字符串(“\ 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

    使用字符串编辑器,可以编辑此字符串;整个字符串形式出现在字符串编辑器的条目,不为七不同项。

    有关这些资源类型的更多信息,请参见 字符串编辑器

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

要求

Header: afxwin.h

请参见

参考

CSingleDocTemplate Class

层次结构图

CDocTemplate::GetDocString

CWinApp::AddDocTemplate

CWinApp::InitInstance

CRuntimeClass Structure

RUNTIME_CLASS