Udostępnij za pośrednictwem


CSingleDocTemplate::CSingleDocTemplate

Konstrukcje CSingleDocTemplate obiektu.

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

Parametry

  • nIDResource
    Określa identyfikator zasobów używane z typu dokumentu.Może to obejmować menu, ikon, akcelerator tabeli i zasobów ciągu.

    Zasób ciągu składa się z maksymalnie siedem podciągów oddzielone znakiem "\n" (znak "\n" jest potrzebny jako symbol zastępczy, jeśli nie jest włączone; podciągu Jednakże końcowe znaki "\n" nie są konieczne); te podciągów opis typu dokumentu.Informacje o podciągów, zobacz CDocTemplate::GetDocString.Ten ciąg zasób znajduje się w pliku zasobu aplikacji.Na przykład:

    // MYCALC.RC

    STRINGTABLE PRELOAD DISCARDABLE

    BEGIN

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

    END

    Można edytować ten ciąg, korzystając z Edytora ciągu; cały ciąg jest wyświetlany jako pojedynczy wpis w edytorze ciąg nie jako oddzielne wpisy siedem.

    Aby uzyskać więcej informacji o tych typach zasobów, zobacz Edytor ciągu.

  • pDocClass
    Wskazuje na CRuntimeClass obiektu klasy dokumentu.Ta klasa jest CDocument-klasy zdefiniować do reprezentowania dokumentów.

  • pFrameClass
    Wskazuje na CRuntimeClass obiektu klasy okna ramki.Ta klasa może być CFrameWnd-klasy lub może być CFrameWnd sobie, jeśli chcesz domyślne zachowanie okna głównego ramki.

  • pViewClass
    Wskazuje na CRuntimeClass obiektu klasy widoku.Ta klasa jest CView-klasy zdefiniować do wyświetlania dokumentów.

Uwagi

Dynamicznie przydzielić CSingleDocTemplate obiektu i przekazać je do CWinApp::AddDocTemplate z InitInstance funkcji składowej klasy aplikacji.

Przykład

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

Wymagania

Nagłówek: afxwin.h

Zobacz też

Informacje

Klasa CSingleDocTemplate

Diagram hierarchii

CDocTemplate::GetDocString

CWinApp::AddDocTemplate

CWinApp::InitInstance

Struktura CRuntimeClass

RUNTIME_CLASS