CSingleDocTemplate::CSingleDocTemplate

Costruisce un oggetto CSingleDocTemplate.

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

Parametri

  • nIDResource
    Specifica l'id delle risorse utilizzate dal tipo di documento.Potrebbe includere il menu, l'icona, la tabella dei tasti di scelta rapida e le risorse di tipo stringa.

    La risorsa di tipo stringa è costituito da un massimo di sette sottostringhe separate dal carattere "\ "n" carattere (\ n" necessario come segnaposto se una sottostringa non è inclusa; tuttavia, i caratteri "\ n" di trascinamento non sono necessari); le sottostringhe descrivono il tipo di documento.Per informazioni sulle sottostringhe, vedere CDocTemplate::GetDocString.Questa risorsa di tipo stringa trovata nel file di risorse dell'applicazione.Di seguito è riportato un esempio:

    // MYCALC.RC

    STRINGTABLE PRELOAD DISCARDABLE

    BEGIN

    IDR_MAINFRAME "MyCalc Windows Application\nSheet\nWorksheet\n Worksheets (*.myc)\n.myc\nMyCalcSheet\n MyCalc Worksheet"

    END

    È possibile modificare questa stringa utilizzando l'editor stringhe, l'intera stringa viene visualizzata come una singola voce nell'editor di stringhe, non come sette voci separate.

    Per ulteriori informazioni su questi tipi di risorsa, vedere Editor di stringhe.

  • pDocClass
    I punti all'oggetto CRuntimeClass di documento classe.Questa classe è CDocumentclasse derivata definito per rappresentare i documenti.

  • pFrameClass
    I punti all'oggetto CRuntimeClass della finestra cornice classe.Questa classe può essere CFrameWndnella classe derivata da, o può essere CFrameWnd stesso se si desidera che il comportamento predefinito della propria finestra cornice principale.

  • pViewClass
    Punti all'oggetto CRuntimeClass della classe di visualizzazione.Questa classe è CViewclasse derivata definito per visualizzare i documenti.

Note

Allocare dinamicamente un oggetto CSingleDocTemplate e passarlo a CWinApp::AddDocTemplate dalla funzione membro InitInstance dell'applicazione.

Esempio

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

Requisiti

Header: afxwin.h

Vedere anche

Riferimenti

Classe di CSingleDocTemplate

Grafico della gerarchia

CDocTemplate::GetDocString

CWinApp::AddDocTemplate

CWinApp::InitInstance

Struttura di CRuntimeClass

RUNTIME_CLASS