다음을 통해 공유


CDocument::OnNewDocument

새 파일 명령으로 프레임 워크에서 호출합니다.

virtual BOOL OnNewDocument( );

반환 값

문서를 성공적으로 초기화 된 경우 0이 아닌. 그렇지 않으면 0입니다.

설명

이 함수의 기본 구현을 호출 하는 DeleteContents 문서 비어 있고 다음 클린으로 새 문서를 표시 하는 멤버 함수입니다.새 문서에 대 한 데이터 구조를 초기화 하려면이 함수를 재정의 합니다.사용자 재정의에서이 함수는 기본 클래스 버전을 호출 해야 합니다.

SDI 응용 프로그램에서 새 파일 명령을 선택할 경우 프레임 워크는이 함수를 사용 하 여 새로 만드는 대신 기존 문서를 다시 초기화 합니다.다중 문서 인터페이스 (MDI) 응용 프로그램에서 파일에 새 사용자를 선택 하면 프레임 워크 때마다 새 문서를 만듭니다 및 다음 초기화 하려면이 함수를 호출 합니다.이 함수 대신 SDI 응용 프로그램에 적용 하려면 새 파일 명령에 대 한 생성자에서 초기화 코드를 배치 해야 합니다.

된 경우 위치 OnNewDocument 두 번 호출 됩니다.이 문서는 ActiveX 문서 서버 역할에 포함 되어 있는 경우 발생 합니다.함수를 먼저 호출 하는 CreateInstance 메서드 (노출의 COleObjectFactory-파생 클래스) 한 번으로는 InitNew 메서드 (노출의 COleServerDoc-클래스를 파생).

예제

다음 예제에서는 문서 개체를 초기화 하는 대체 메서드를 보여 줍니다.

// Method 1: In an MDI application, the simplest place to do 
// initialization is in the document constructor.  The framework 
// always creates a new document object for File New or File Open.
CExampleDoc::CExampleDoc()
{
   // Do initialization of MDI document here.
}
// Method 2: In an SDI or MDI application, do all initialization 
// in an override of OnNewDocument, if you are certain that
// the initialization is effectively saved upon File Save
// and fully restored upon File Open, via serialization.
BOOL CMyDoc::OnNewDocument()
{
   if (!CDocument::OnNewDocument())
      return FALSE;

   // Do initialization of new document here.

   return TRUE;
}
// Method 3: If the initialization of your document is not
// effectively saved and restored by serialization (during File Save
// and File Open), then implement the initialization in single
// function (named InitMyDocument in this example).  Call the
// shared initialization function from overrides of both
// OnNewDocument and OnOpenDocument.
BOOL CExampleDoc::OnNewDocument()
{
   if (!CDocument::OnNewDocument())
      return FALSE;

   InitMyDocument(); // call your shared initialization function

   // If your new document object requires additional initialization
   // not necessary when the document is deserialized via File Open,
   // then perform that additional initialization here.

   return TRUE;
}

요구 사항

헤더: afxwin.h

참고 항목

참조

CDocument 클래스

계층 구조 차트

CDocument::CDocument

CDocument::DeleteContents

CDocument::OnCloseDocument

CDocument::OnOpenDocument

CDocument::OnSaveDocument