다음을 통해 공유


CSingleDocTemplate 클래스

SDI(단일 문서 인터페이스)를 구현하는 문서 템플릿을 정의합니다.

구문

class CSingleDocTemplate : public CDocTemplate

멤버

공용 생성자

속성 설명
CSingleDocTemplate::CSingleDocTemplate CSingleDocTemplate 개체를 생성합니다.

설명

SDI 애플리케이션은 기본 프레임 창을 사용하여 문서를 표시합니다. 한 번에 하나의 문서만 열 수 있습니다.

문서 템플릿은 다음 세 가지 유형의 클래스 간의 관계를 정의합니다.

  • 에서 파생 CDocument되는 문서 클래스입니다.

  • 위에 나열된 문서 클래스의 데이터를 표시하는 뷰 클래스입니다. 이 클래스는 , CScrollView또는 CFormViewCEditView.에서 CView파생할 수 있습니다. (직접 사용할 CEditView 수도 있습니다.)

  • 보기를 포함하는 프레임 창 클래스입니다. SDI 문서 템플릿의 경우 이 클래스를 CFrameWnd파생시킬 수 있습니다. 기본 프레임 창의 동작을 사용자 지정할 필요가 없는 경우 고유한 클래스를 파생하지 않고 직접 사용할 CFrameWnd 수 있습니다.

SDI 애플리케이션은 일반적으로 한 가지 유형의 문서를 지원하므로 하나의 CSingleDocTemplate 개체만 있습니다. 한 번에 하나의 문서만 열 수 있습니다.

생성자를 제외한 멤버 함수를 CSingleDocTemplate 호출할 필요가 없습니다. 프레임워크는 내부적으로 개체를 처리합니다 CSingleDocTemplate .

사용에 CSingleDocTemplate대한 자세한 내용은 문서 서식 파일 및 문서/보기 만들기 프로세스를 참조 하세요.

상속 계층 구조

CObject

CCmdTarget

Cdoctemplate

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개의 개별 항목이 아니라 문자열 편집기에서 단일 항목으로 나타납니다.

이러한 리소스 종류에 대한 자세한 내용은 문자열 편집기를 참조하세요.

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

참고 항목

MFC 샘플 DOCKTOOL
CDocTemplate 클래스
계층 구조 차트
CDocTemplate 클래스
CDocument 클래스
CFrameWnd 클래스
CMultiDocTemplate 클래스
CView 클래스
CWinApp 클래스