다음을 통해 공유


CDocument::OnOpenDocument

프레임 워크 파일 열기 명령의 일부로 호출 됩니다.

virtual BOOL OnOpenDocument(
   LPCTSTR lpszPathName 
);

매개 변수

  • lpszPathName
    열려는 문서의 경로 가리킵니다.

반환 값

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

설명

이 함수는 기본 구현 호출 지정 된 파일을 엽니다의 DeleteContents 문서 비어 있는지 확인 하는 멤버 함수를 호출 CObject::Serialize 읽을 파일의 내용을 다음 클린 문서로 표시 하 고 있습니다.보관 메커니즘 또는 파일 메커니즘 이외의 정보를 사용 하려는 경우이 함수를 재정의 합니다.예를 들어, 문서가 별도 파일 대신 데이터베이스에서 레코드를 나타내는 위치는 응용 프로그램을 작성할 수 있습니다.

SDI 응용 프로그램에서 파일 열기 명령을 선택할 경우 프레임 워크는이 함수를 사용 하 여 기존 다시 초기화 하 CDocument 개체는 새로 만드는 대신.MDI 응용 프로그램에서 파일 열기를 선택 하면 프레임 워크는 새 구문 CDocument 때마다 개체 초기화 하려면이 함수를 호출 합니다.이 함수 대신 SDI 응용 프로그램에 적용 되도록 파일 열기 명령에 대 한 생성자에서 초기화 코드를 배치 해야 합니다.

예제

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

// 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;
}
// Additional example of OnOpenDocument()
BOOL CExampleDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
   if (!CDocument::OnOpenDocument(lpszPathName))
      return FALSE;

   InitMyDocument(); // call your shared initialization function

   return TRUE;
}

요구 사항

헤더: afxwin.h

참고 항목

참조

CDocument 클래스

계층 구조 차트

CDocument::DeleteContents

CDocument::OnCloseDocument

CDocument::OnNewDocument

CDocument::OnSaveDocument

CDocument::ReportSaveLoadException

CObject::Serialize