본문 바로가기

Language/MFC

4대클래스 자동생성 소스 분석[CDocument]


자동생성 클래스 분석 - CDocument

 

CDocument 클래스

 

CLyraDoc 클래스는 CDocument 클래스를 상속받은 것이다.

CDocument 클래스는 일종의 데이터 임시 저장소이다. CLyraDoc와 CView는 연결되어 있다. 이

것을 확인하려면 LyraView.cpp에서 찾아볼 수 있을 것이다. 즉, 이 말들을 정리하면 VIEW 창에

나타내기를 원하는 것을 CDocument 클래스에 넣으면 된다는 뜻이다.

 

BEGIN_MESSAGE_MAP(CLyraDoc, CDocument)

 

//{{AFX_MSG_MAP(CLyraDoc)

// NOTE - the Classwizard will add and remove mapping macros here.

// DO NOT EDIT what you see in these blocks

of generated code!

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

CLyraDoc::CLyraDoc()

{

// TODO: add one-time construction code here

 

생성자

}

 

CLyraDoc::CLyraDoc()

{

 

소멸자

}

 

OnNewDocument 함수는 팝업 메뉴 new나 OnFileNew() 함수를 실행하여서 새로운 파일이 생성될

때 실행되는 함수이다.

지금 현재는 아무것도 없으므로 아버지 클래스인 CDocument만 실행된다.

 

BOOL CLyraDoc::OnNewDocument()

{

 

if (!CDocument::OnNewDocument())

return FALSE;

// TODO: add reinitialization code here

// (SDI documents will reuse this document)

 

return TRUE;

 

}

 

Serialize 함수는 메모리에 있는 데이터를 저장 장치와 연결시키거나 열어주는 함수입니다.

 

 

void CLyraDoc::Serialize(CArchive& ar)

{

 

if (ar.IsStoring())

{

// 파일로 저장할 때

}

else

{

// 파일에서 불러올 때

}

 

}