Chapter 06 MFC Dialog Control Class Contents CDialog

  • Slides: 128
Download presentation
Chapter 06 MFC Dialog 와 Control Class

Chapter 06 MFC Dialog 와 Control Class

Contents CDialog class Common Dialogs Property Sheets Control classes 1 비트교육센터

Contents CDialog class Common Dialogs Property Sheets Control classes 1 비트교육센터

CDialog Class (cont’d) History – MFC 1. 0 Modal dialog : CModal. Dialog Modeless

CDialog Class (cont’d) History – MFC 1. 0 Modal dialog : CModal. Dialog Modeless dialog : CDialog – Current version Modal dialog : CDialog Modeless dialog : Cdialog – AFXWIN. H // all CModal. Dialog functionality is now in CDialog #define CModal. Dialog CDialog 3 비트교육센터

CDialog Class (cont’d) void CMy. View: : Display. Order. Dialog() { CMy. Dialog my.

CDialog Class (cont’d) void CMy. View: : Display. Order. Dialog() { CMy. Dialog my. Dialog(ID_DLG_MYDIALOG); if ( my. Dialog. Do. Modal() == IDOK ) { // Do OK processing } else { // Do Calnel processing } } m_p. Dlg. My. Dlg. Ptr = new CMy. Dialog; m_p. Dlg. My. Dlg. Ptr->Create(ID_DLG_MYDIALOG); // Do something m_p. Dlg. My. Dlg. Ptr->Destroy. Window(); m_p. Dlg. My. Dlg. Ptr = NULL; 4 비트교육센터

Win 32 APIs Dialog생성을 위한 Win 32 APIs – Create. Dialog() Modeless dialog생성, template

Win 32 APIs Dialog생성을 위한 Win 32 APIs – Create. Dialog() Modeless dialog생성, template resource이용 – Create. Dialog. Indirect() Modeless dialog생성, template pointer이용 Modal()/Modaless를 만들때 모두 사용되는 함수 – Dialog. Box() Modal dialog생성, template resource이용 – Dialog. Box. Indirect() Modal dialog생성, template pointer이용 5 비트교육센터

Win 32 APIs (cont’d) CDialog Class – – 오직 Create. Dialog. Indirect() API을 이용

Win 32 APIs (cont’d) CDialog Class – – 오직 Create. Dialog. Indirect() API을 이용 Modality를 내부적으로 구현 AFXWIN. H DLGCORE. CPP, AFXWIN 2. INL 6 비트교육센터

CDialog class CDialog : public CWnd { DECLARE_DYNAMIC(CDialog) BOOL Create(LPCTSTR lpsz. Template. Name, CWnd*

CDialog class CDialog : public CWnd { DECLARE_DYNAMIC(CDialog) BOOL Create(LPCTSTR lpsz. Template. Name, CWnd* p. Parent. Wnd = NULL); BOOL Create(UINT n. IDTemplate, CWnd* p. Parent. Wnd = NULL); BOOL Create. Indirect(LPCDLGTEMPLATE lp. Dialog. Template, CWnd* p. Parent. Wnd = NULL, void* lp. Dialog. Init = NULL); BOOL Create. Indirect(HGLOBAL h. Dialog. Template, CWnd* p. Parent. Wnd = NULL); // Modal construct public: CDialog(LPCTSTR lpsz. Template. Name, CWnd* p. Parent. Wnd = NULL); CDialog(UINT n. IDTemplate, CWnd* p. Parent. Wnd = NULL); BOOL Init. Modal. Indirect(LPCDLGTEMPLATE lp. Dialog. Template, CWnd* p. Parent. Wnd = NULL, void* lp. Dialog. Init = NULL); BOOL Init. Modal. Indirect(HGLOBAL h. Dialog. Template, CWnd* p. Parent. Wnd = NULL); // Operations public: // modal processing virtual int Do. Modal(); 7 비트교육센터

CDialog (cont’d) void Next. Dlg. Ctrl() const; void Prev. Dlg. Ctrl() const; void Goto.

CDialog (cont’d) void Next. Dlg. Ctrl() const; void Prev. Dlg. Ctrl() const; void Goto. Dlg. Ctrl(CWnd* p. Wnd. Ctrl); // termination void End. Dialog(int n. Result); // Overridables (special message map entries) virtual BOOL On. Init. Dialog(); virtual void On. Set. Font(CFont* p. Font); protected: virtual void On. OK(); virtual void On. Cancel(); // Implementation public: virtual ~CDialog(); virtual BOOL Pre. Translate. Message(MSG* p. Msg); virtual BOOL On. Cmd. Msg(UINT n. ID, int n. Code, void* p. Extra, AFX_CMDHANDLERINFO* p. Handler. Info); virtual BOOL Check. Auto. Center(); 8 비트교육센터

CDialog (cont’d) protected: // parameters for 'Do. Modal' LPCTSTR m_lpsz. Template. Name; // name

CDialog (cont’d) protected: // parameters for 'Do. Modal' LPCTSTR m_lpsz. Template. Name; // name or MAKEINTRESOURCE HGLOBAL m_h. Dialog. Template; // indirect (m_lp. Dialog. Template == NULL) LPCDLGTEMPLATE m_lp. Dialog. Template; void* m_lp. Dialog. Init; // DLGINIT resource data CWnd* m_p. Parent. Wnd; // parent/owner window HWND m_h. Wnd. Top; // top level parent window (may be disabled) virtual void Pre. Init. Dialog(); // implementation helpers HWND Pre. Modal(); void Post. Modal(); BOOL Create. Indirect(LPCDLGTEMPLATE lp. Dialog. Template, CWnd* p. Parent. Wnd, void* lp. Dialog. Init, HINSTANCE h. Inst); BOOL Create. Indirect(HGLOBAL h. Dialog. Template, CWnd* p. Parent. Wnd, HINSTANCE h. Inst); protected: DECLARE_MESSAGE_MAP() }; 9 비트교육센터

CDialog (cont’d) Declaration(AFXWIN. H) – 멤버 변수 m_n. IDHelp – Button을 위한 help ID

CDialog (cont’d) Declaration(AFXWIN. H) – 멤버 변수 m_n. IDHelp – Button을 위한 help ID m_lpsz. Template. Name – Resource template의 이름 m_h. Dialog. Template – 일단 load된 후의 resource template의 handle m_lp. Dialog. Init – 초기화에 관련된 data에 대한 pointer 10 비트교육센터

CDialog (cont’d) m_p. Parent. Wnd – Parent window에 대한 pointer m_h. Wnd. Top –

CDialog (cont’d) m_p. Parent. Wnd – Parent window에 대한 pointer m_h. Wnd. Top – Top-level parent window m_p. Occ. Dialog. Info – OLE controls을 위한 stored information – 멤버 함수 virtual Pre. Translate. Message() – 특별한 message(tool tips, context-sensitive help)에 대한 filtering 11 비트교육센터

CDialog (cont’d) virtual On. Cmd. Msg() – Command message처리작업 virtual Check. Auto. Center() –

CDialog (cont’d) virtual On. Cmd. Msg() – Command message처리작업 virtual Check. Auto. Center() – Auto-center옵션이 체크되었는지 확인 virtual Set. Occ. Dialog. Info() – M_p. Occ. Dialog. Info변수에 데이터를 setting virtual Pre. Init. Dialog() – WM_INITDIALOG message이전에 불리워지는 함수 Pre. Modal() – Do. Modal()함수 실행을 위한 준비작업 Post. Modal() – Do. Modal()함수가 끝난후의 뒤처리 12 비트교육센터

Modal Dialog Creation (cont’d) “Dlg. Core. cpp” CDialog: : CDialog(LPCTSTR lpsz. Template. Name, CWnd*

Modal Dialog Creation (cont’d) “Dlg. Core. cpp” CDialog: : CDialog(LPCTSTR lpsz. Template. Name, CWnd* p. Parent. Wnd) { m_p. Parent. Wnd = p. Parent. Wnd; m_lpsz. Template. Name = lpsz. Template. Name; if (HIWORD(m_lpsz. Template. Name) == 0) m_n. IDHelp = LOWORD((DWORD)m_lpsz. Template. Name); } CDialog: : CDialog(UINT n. IDTemplate, CWnd* p. Parent. Wnd) { m_p. Parent. Wnd = p. Parent. Wnd; m_lpsz. Template. Name = MAKEINTRESOURCE(n. IDTemplate); m_n. IDHelp = n. IDTemplate; } 14 비트교육센터

Modal Dialog Creation (cont’d) int CDialog: : Do. Modal() { // STEP 1 :

Modal Dialog Creation (cont’d) int CDialog: : Do. Modal() { // STEP 1 : load resource as necessary(리소스 로드) – 모달/모스 공통 LPCDLGTEMPLATE lp. Dialog. Template = m_lp. Dialog. Template; HGLOBAL h. Dialog. Template = m_h. Dialog. Template; HINSTANCE h. Inst = Afx. Get. Resource. Handle(); if (m_lpsz. Template. Name != NULL) { h. Inst = Afx. Find. Resource. Handle(m_lpsz. Template. Name, RT_DIALOG); HRSRC h. Resource = : : Find. Resource(h. Inst, m_lpsz. Template. Name, RT_DIALOG); h. Dialog. Template = Load. Resource(h. Inst, h. Resource); } if (h. Dialog. Template != NULL) lp. Dialog. Template = (LPCDLGTEMPLATE)Lock. Resource (h. Dialog. Template); // return -1 in case of failure to load the dialog template resource if (lp. Dialog. Template == NULL) return -1; 15 비트교육센터

Modal Dialog Creation (cont’d) // STEP 2 : Preparing to create the dialog(준비과정) HWND

Modal Dialog Creation (cont’d) // STEP 2 : Preparing to create the dialog(준비과정) HWND h. Wnd. Parent = Pre. Modal(); 부모윈도우 핸들값을 가져온다. Afx. Unhook. Window. Create(); BOOL b. Enable. Parent = FALSE; if (h. Wnd. Parent != NULL && : : Is. Window. Enabled(h. Wnd. Parent)) { : : Enable. Window(h. Wnd. Parent, FALSE); 부모윈도우를 죽이고 b. Enable. Parent = TRUE; } // STEP 3 : create modeless dialog(모달리스 하나를 만든다. ) Afx. Hook. Window. Create(this); if (Create. Dlg. Indirect(lp. Dialog. Template, 모달리스를 띄운다. CWnd: : From. Handle(h. Wnd. Parent), h. Inst)) { if (m_n. Flags & WF_CONTINUEMODAL) { // enter modal loop DWORD dw. Flags = MLF_SHOWONIDLE; if (Get. Style() & DS_NOIDLEMSG) dw. Flags |= MLF_NOIDLEMSG; VERIFY(Run. Modal. Loop(dw. Flags) == m_n. Modal. Result); } CWnd Run함수를 대치한다. 16 비트교육센터

Modal Dialog Creation (cont’d) } // hide the window before enabling the parent, etc.

Modal Dialog Creation (cont’d) } // hide the window before enabling the parent, etc. if (m_h. Wnd != NULL) Set. Window. Pos(NULL, 0, 0, SWP_HIDEWINDOW| SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER); 자신의 다이얼로그를 숨기고 if (b. Enable. Parent) : : Enable. Window(h. Wnd. Parent, TRUE); 부모윈도우를 활성화한다. if (h. Wnd. Parent != NULL && : : Get. Active. Window() == m_h. Wnd) : : Set. Active. Window(h. Wnd. Parent); // STEP 4 : destroy modal window Destroy. Window(); 그리고 죽인다. Post. Modal(); } 17 비트교육센터

Modal Dialog Creation (cont’d) HWND CDialog: : Pre. Modal() 부모윈도우의 핸들값을 가져오는 함수 {

Modal Dialog Creation (cont’d) HWND CDialog: : Pre. Modal() 부모윈도우의 핸들값을 가져오는 함수 { // cannot call Do. Modal on a dialog already constructed as modeless ASSERT(m_h. Wnd == NULL); // allow OLE servers to disable themselves CWin. App* p. App = Afx. Get. App(); if (p. App != NULL) p. App->Enable. Modeless(FALSE); // find parent HWND h. Wnd = CWnd: : Get. Safe. Owner_ (m_p. Parent. Wnd->Get. Safe. Hwnd(), &m_h. Wnd. Top); // hook for creation of dialog Afx. Hook. Window. Create(this); // return window to use as parent for dialog return h. Wnd; 부모 핸들 } 18 비트교육센터

Modal Dialog Creation (cont’d) int CWnd: : Run. Modal. Loop(DWORD dw. Flags) CWnd Run함수를

Modal Dialog Creation (cont’d) int CWnd: : Run. Modal. Loop(DWORD dw. Flags) CWnd Run함수를 대치한다. { CWnd에 존재한다. (다이얼로그 이외의 다른 클레스에서도 사용된다는 의미) BOOL b. Idle = TRUE; LONG l. Idle. Count = 0; BOOL b. Show. Idle = (dw. Flags & MLF_SHOWONIDLE) && !(Get. Style() & WS_VISIBLE); HWND h. Wnd. Parent = : : Get. Parent(m_h. Wnd); // acquire and dispatch messages until the modal state is done for (; ; ) { // phase 1: check to see if we can do idle work while(b. Idle&&!: : Peek. Message(p. Msg, NULL, PM_NOREMOVE)) { } // phase 2: pump messages while available do { // pump message, but quit on WM_QUIT !Afx. Get. Thread()->Pump. Message(); } while (: : Peek. Message(p. Msg, NULL, PM_NOREMOVE)); } } 19 비트교육센터

Modal Dialog Creation (cont’d) Do. Modal()(DLGCORE. CPP) – Dialog resource의 loading Dialog template name을

Modal Dialog Creation (cont’d) Do. Modal()(DLGCORE. CPP) – Dialog resource의 loading Dialog template name을 가지고 dialog template을 찾아서 load함 – Dialog를 생성하기 위한 준비 Pre. Modal()함수를 호출함 – Safety checks Parent window handle을 찾음 – m_h. Wnd. Top에 저장 Enable. Window(FALSE)를 호출 – Parent window를 disable시킴 20 비트교육센터

Modal Dialog Creation (cont’d) – Dialog를 생성하고 보여줌 CWnd: : Create. Dlg. Indirect()함수 호출

Modal Dialog Creation (cont’d) – Dialog를 생성하고 보여줌 CWnd: : Create. Dlg. Indirect()함수 호출 내부적으로 Win 32 API인 Create. Dialog. Indirect()를 호출 CWnd: : Run. Modal. Loop()함수 호출 Dialog가 끝날때 까지 일을 수행 사용자가 ok나 cancel버튼을 누르면 CWnd: : End. Modal. Loop()함수가 호출됨 Dialog를 화면에서 보이지 않게 함 Dialog가 종료하면 Enable. Window(TRUE)를 호출 Parent window를 enable시킴 – 마지막 단계 Destroy. Window()함수 호출 Post. Modal()함수 호출 21 비트교육센터

Modeless Dialog Creation Modeless dialog creation – 두가지 과정을 거침 New operator를 사용하여 변수

Modeless Dialog Creation Modeless dialog creation – 두가지 과정을 거침 New operator를 사용하여 변수 생성 힙메모리에 변수 생성 CDialog: : Create()함수 호출 22 비트교육센터

Modeless Dialog Creation (cont’d) BOOL CDialog: : Create(LPCTSTR lpsz. Template. Name, CWnd* p. Parent.

Modeless Dialog Creation (cont’d) BOOL CDialog: : Create(LPCTSTR lpsz. Template. Name, CWnd* p. Parent. Wnd) { m_lpsz. Template. Name = lpsz. Template. Name; // used for help if (HIWORD(m_lpsz. Template. Name) == 0 && m_n. IDHelp == 0) m_n. IDHelp = LOWORD((DWORD)m_lpsz. Template. Name); if (!_Afx. Check. Dialog. Template(lpsz. Template. Name, FALSE)) { Post. Nc. Destroy(); // cleanup if Create fails too soon return FALSE; } HINSTANCE h. Inst = Afx. Find. Resource. Handle(lpsz. Template. Name, RT_DIALOG); HRSRC h. Resource = : : Find. Resource(h. Inst, lpsz. Template. Name, RT_DIALOG); HGLOBAL h. Template = Load. Resource(h. Inst, h. Resource); BOOL b. Result = Create. Indirect(h. Template, p. Parent. Wnd, h. Inst); Free. Resource(h. Template); return b. Result; } 23 비트교육센터

Modeless Dialog Creation (cont’d) BOOL CDialog: : Create. Indirect (LPCDLGTEMPLATE lp. Dialog. Template, CWnd*

Modeless Dialog Creation (cont’d) BOOL CDialog: : Create. Indirect (LPCDLGTEMPLATE lp. Dialog. Template, CWnd* p. Parent. Wnd, void* lp. Dialog. Init, HINSTANCE h. Inst) { ASSERT(lp. Dialog. Template != NULL); if (p. Parent. Wnd == NULL) p. Parent. Wnd = Afx. Get. Main. Wnd(); m_lp. Dialog. Init = lp. Dialog. Init; return Create. Dlg. Indirect(lp. Dialog. Template, p. Parent. Wnd, h. Inst); } 24 비트교육센터

Modeless Dialog Creation (cont’d) CDialog: : Create()(DLGCORE. CPP) – Template name과 help ID를 내부

Modeless Dialog Creation (cont’d) CDialog: : Create()(DLGCORE. CPP) – Template name과 help ID를 내부 변수에 저장 – Dialog resource를 찾고 load함 – CDialog: : Create. Indirect()함수 호출 내부적으로 Win 32 API인 Create. Dialog. Indirect()함수 호출 – 사용자가 ok나 cancel버튼을 누르면 End. Dialog()가 호출되어 dialog가 사라짐 25 비트교육센터

Dialog Terminator void CDialog: : End. Dialog(int n. Result) { ASSERT(: : Is. Window(m_h.

Dialog Terminator void CDialog: : End. Dialog(int n. Result) { ASSERT(: : Is. Window(m_h. Wnd)); if (m_n. Flags & (WF_MODALLOOP|WF_CONTINUEMODAL)) End. Modal. Loop(n. Result); : : End. Dialog(m_h. Wnd, n. Result); } 26 비트교육센터

CDialog Control Initialization Dialog에 있는 control의 초기화 작업 – Resource에 의한 초기화 – Combo

CDialog Control Initialization Dialog에 있는 control의 초기화 작업 – Resource에 의한 초기화 – Combo box를 예로 살펴봄 Data는 “one”, “two”, “three”라 가정 – 다음과 같은 코드가 생성되지 않는다. m_p. Combo->Add. String(“one”); m_p. Combo->Add. String(“two”); m_p. Combo->Add. String(“three”); 27 비트교육센터

CDialog Control Initialization (cont’d) WM_INITDIALOG – Dialog가 화면에 보이기 전에 발생하는 message – Application으로

CDialog Control Initialization (cont’d) WM_INITDIALOG – Dialog가 화면에 보이기 전에 발생하는 message – Application으로 하여금 dialog에 있는 control들을 초기화 할 수 있도록 함 – CDialog: : Handle. Init. Dialog()함수에 mapping되어 있음 CDialog: : Handle. Init. Dialog() – OLE control 관련 초기화 작업을 하고 CDialog: : On. Init. Dialog()를 호출 CDialog: : On. Init. Dialog() – CWnd: : Execute. Dlg. Init()를 호출 28 비트교육센터

CDialog Control Initialization (cont’d) – Resource file 예제를 쎃넣을 경우 다음과 같은 내용이 첨부된다.

CDialog Control Initialization (cont’d) – Resource file 예제를 쎃넣을 경우 다음과 같은 내용이 첨부된다. IDD_ABOUTBOX DLGINIT BEGIN IDC_COMBO 1, 0 x 403, 4, 0 0 x 6 e 6 f, 0 x 0065, IDC_COMBO 1, 0 x 403, 4, 0 0 x 7774, 0 x 006 f, IDC_COMBO 1, 0 x 403, 6, 0 0 x 6874, 0 x 6572, 0 x 0065, 0 END 29 비트교육센터

CDialog Control Initialization (cont’d) CWnd: : Execute. Dlg. Init()(WINCORE. CPP) – 두가지 버전이 존재

CDialog Control Initialization (cont’d) CWnd: : Execute. Dlg. Init()(WINCORE. CPP) – 두가지 버전이 존재 Argument로 dialog template name Argument로 dialog data에 대한 pointer – 일단 첫번째 버전의 함수가 dialog template name을 가지고 resource 파일에서 control의 data를 load함 – 이 후 pointer를 얻어서 두번째 버전의 함수를 호출 – why CWnd class member function? 30 비트교육센터

CDialog Control Initialization (cont’d) CWnd: : Execute. Dlg. Init(LPVOID) – Resource file의 raw data(DLGINIT)를

CDialog Control Initialization (cont’d) CWnd: : Execute. Dlg. Init(LPVOID) – Resource file의 raw data(DLGINIT)를 parsing함 리소스파일의 시작주소 BOOL CWnd: : Execute. Dlg. Init(LPVOID lp. Resource) { BOOL b. Success = TRUE; UNALIGNED WORD* lpn. Res = (WORD*)lp. Resource; while(b. Success && *lpn. Res != 0) { WORD n. IDC = *lpn. Res++; WORD n. Msg = *lpn. Res++; DWORD dw. Len = *((UNALIGNED DWORD*&)lpn. Res)++; Add. String등의 동일한 작업을 할수 있게 if문 작성됨 if (n. Msg == LB_ADDSTRING || n. Msg == CB_ADDSTRING) { if (: : Send. Dlg. Item. Message. A(m_h. Wnd, n. IDC, n. Msg, 0, (LONG)lpn. Res) == -1) b. Success = FALSE; } } return b. Success; } 31 비트교육센터

DDX/DDV – – DDX(Dynamic Data e. Xchange) DDV(Dynamic Data Validation) Data members Controls 활용

DDX/DDV – – DDX(Dynamic Data e. Xchange) DDV(Dynamic Data Validation) Data members Controls 활용 사례 실제 데이터교환이 이루어지는장소 void CMy. Dlg: : Do. Data. Exchange(CData. Exchange * p. DX) { CDialog: : Do. Data. Exchange(p. DX); DDX_Text(p. DX, IDC_EDIT 1, m_str. Edit 1); DDV_Max. Chars(p. DX, IDC_EDIT 1, 20); DDX_Text(p. DX, IDC_EDIT 2, m_u. Edit 2); DDV_Min. Max. Chars(p. DX, IDC_EDIT 2, 1, 234); DDX_Check(p. DX, IDC_CHECK, m_b. Check. State); DDX_Radio(p. DX, IDC_RADIO, m_n. Radio. State); } 32 비트교육센터

DDX/DDV (cont’d) Helper class – CData. Exchange(AFXWIN. H) class CData. Exchange { // Attributes

DDX/DDV (cont’d) Helper class – CData. Exchange(AFXWIN. H) class CData. Exchange { // Attributes public: BOOL m_b. Save. And. Validate; // TRUE => save and validate data CWnd* m_p. Dlg. Wnd; // container usually a dialog // Operations (for implementors of DDX and DDV procs) HWND Prepare. Ctrl(int n. IDC); // return HWND of control HWND Prepare. Edit. Ctrl(int n. IDC); // return HWND of control void Fail(); // will throw exception CWnd* Prepare. Ole. Ctrl(int n. IDC); // for OLE controls in dialog // Implementation CData. Exchange(CWnd* p. Dlg. Wnd, BOOL b. Save. And. Validate); HWND m_h. Wnd. Last. Control; // last control used (for validation) BOOL m_b. Edit. Last. Control; // last control was an edit item }; 34 비트교육센터

DDX/DDV (cont’d) 멤버 변수 – m_b. Save. And. Validate TRUE data가 control에서 변수로 감

DDX/DDV (cont’d) 멤버 변수 – m_b. Save. And. Validate TRUE data가 control에서 변수로 감 FALSE data가 변수에서 control로 감 Validation은 TRUE일때만 일어남 – m_p. Dlg. Wnd Dialog에 대한 CWnd pointer – m_h. Wnd. Last. Control Previous control에 대한 handle을 저장 – m_b. Edit. Last. Control Previous control이 수정되었는지를 저장 35 비트교육센터

DDX/DDV (cont’d) 멤버 함수 – Constructor – Prepare. Ctrl() Non-edit control을 위한 준비 –

DDX/DDV (cont’d) 멤버 함수 – Constructor – Prepare. Ctrl() Non-edit control을 위한 준비 – Prepare. Edit. Ctrl() Edit control을 위한 준비 – Fail() Validation이 실패하면 호출됨 Focus를 previous control로 보내고 CUser. Exception예외를 발생시킴 – Prepare. Ole. Ctrl() OLE control을 위한 준비 36 비트교육센터

DDX/DDV (cont’d) 특징 – – DDX/DDV는 Serialize과정과 유사 CData. Exchange 는 CArchive 와 비슷

DDX/DDV (cont’d) 특징 – – DDX/DDV는 Serialize과정과 유사 CData. Exchange 는 CArchive 와 비슷 Do. Data. Exchange()는 Serialize() 와 비슷 Save/load tag를 가짐 37 비트교육센터

DDX/DDV (cont’d) DDX/DDV 함수들 – DDX_Text()(DLGDATA. CPP) m_b. Save. And. Validate의 값을 기준으로 data이동

DDX/DDV (cont’d) DDX/DDV 함수들 – DDX_Text()(DLGDATA. CPP) m_b. Save. And. Validate의 값을 기준으로 data이동 – DDV_Max. Chars()(DLGDATA. CPP) m_b. Save. And. Validate값이 TRUE인경우 validation코드 수행 – DDX_Text. With. Format()(DLGDATA. CPP) String과 int사이의 conversion 38 비트교육센터

DDX/DDV (cont’d) void AFXAPI DDX_Text(CData. Exchange* p. DX, int n. IDC, CString& value) {

DDX/DDV (cont’d) void AFXAPI DDX_Text(CData. Exchange* p. DX, int n. IDC, CString& value) { HWND h. Wnd. Ctrl = p. DX->Prepare. Edit. Ctrl(n. IDC); if (p. DX->m_b. Save. And. Validate) { int n. Len = : : Get. Window. Text. Length(h. Wnd. Ctrl); : : Get. Window. Text(h. Wnd. Ctrl, value. Get. Buffer. Set. Length(n. Len), n. Len+1); value. Release. Buffer(); } else { Afx. Set. Window. Text(h. Wnd. Ctrl, value); 맴버변수에서 컨트롤로(FALSE) } } 39 비트교육센터

DDX/DDV (cont’d) void AFXAPI DDV_Max. Chars(CData. Exchange* p. DX, CString const& value, int n.

DDX/DDV (cont’d) void AFXAPI DDV_Max. Chars(CData. Exchange* p. DX, CString const& value, int n. Chars) 예)범위에 맞는지 틀린지 check { ASSERT(n. Chars >= 1); // allow them something if (p. DX->m_b. Save. And. Validate && value. Get. Length() > n. Chars) { TCHAR sz. T[32]; wsprintf(sz. T, _T("%d"), n. Chars); CString prompt; Afx. Format. String 1(prompt, AFX_IDP_PARSE_STRING_SIZE, sz. T); Afx. Message. Box(prompt, MB_ICONEXCLAMATION, AFX_IDP_PARSE_STRING_SIZE); prompt. Empty(); // exception prep p. DX->Fail(); } else if (p. DX->m_h. Wnd. Last. Control != NULL && p. DX->m_b. Edit. Last. Control) { // limit the control max-chars automatically : : Send. Message(p. DX->m_h. Wnd. Last. Control, EM_LIMITTEXT, n. Chars, 0); } } 비트교육센터 40

DDX/DDV (cont’d) BOOL CWnd: : Update. Data(BOOL b. Save. And. Validate) { CData. Exchange

DDX/DDV (cont’d) BOOL CWnd: : Update. Data(BOOL b. Save. And. Validate) { CData. Exchange dx(this, b. Save. And. Validate); _AFX_THREAD_STATE* p. Thread. State = Afx. Get. Thread. State(); HWND h. Wnd. Old. Lockout = p. Thread. State->m_h. Lockout. Notify. Window; ASSERT(h. Wnd. Old. Lockout != m_h. Wnd); // must not recurse p. Thread. State->m_h. Lockout. Notify. Window = m_h. Wnd; BOOL b. OK = FALSE; // assume failure TRY { Do. Data. Exchange(&dx); b. OK = TRUE; // it worked } CATCH(CUser. Exception, e) { // validation failed - user already alerted, fall through ASSERT(!b. OK); } } 42 비트교육센터

DDX/DDV (cont’d) void CDialog: : On. OK(){ if (!Update. Data(TRUE)) { TRACE 0("Update. Data

DDX/DDV (cont’d) void CDialog: : On. OK(){ if (!Update. Data(TRUE)) { TRACE 0("Update. Data failed during dialog termination. n"); // the Update. Data routine will set focus to correct item return; } End. Dialog(IDOK); } BOOL CDialog: : On. Init. Dialog(){ BOOL b. Dlg. Init; if (m_lp. Dialog. Init != NULL) b. Dlg. Init = Execute. Dlg. Init(m_lp. Dialog. Init); else b. Dlg. Init = Execute. Dlg. Init(m_lpsz. Template. Name); Update. Data(FALSE); return TRUE; // set focus to first one } 43 비트교육센터

Common Dialogs – 표준 interface제공을 위하여 – 종류 CColor. Dialog CFile. Dialog CFind. Replace.

Common Dialogs – 표준 interface제공을 위하여 – 종류 CColor. Dialog CFile. Dialog CFind. Replace. Dialog CFont. Dialog CPrint. Dialog CPage. Setup. Dialog ( MFC 4. 0 ) 44 비트교육센터

Common Dialogs (cont’d) Steps – 생성자 호출 – Do. Modal() 호출 – IDOK가 리턴될

Common Dialogs (cont’d) Steps – 생성자 호출 – Do. Modal() 호출 – IDOK가 리턴될 때 적절한 처리 CFile. Dialog my. Dialog(TRUE, NULL, OFN_FILEMUSTEXIST); if ( my. Dialog. Do. Modal() == IDOK ) { Cstring str. Path = my. Dialog. Get. Path. Name(); CString str. File = my. Dialog. Get. File. Name(); } else // User selected Cancel … 45 비트교육센터

Common Dialogs (cont’d) Win 32 API 관점에서 – 모든 common dialog는 대응되는 structure를 가지고

Common Dialogs (cont’d) Win 32 API 관점에서 – 모든 common dialog는 대응되는 structure를 가지고 있다. 대응되는 API를 가지고 있다. 예) Open File common dialog – Structure – OPENFILENAME – API – Get. Open. File. Name(LP OPENFILENAME) 모든 common dialog의 base class – CCommon. Dialog(AFXDLGS. H) – On. OK()와 On. Cancel() 추가 46 비트교육센터

Common Dialogs (cont’d) 예제 dialog – CFile. Dialog(AFXDLGS. H) class CFile. Dialog : public

Common Dialogs (cont’d) 예제 dialog – CFile. Dialog(AFXDLGS. H) class CFile. Dialog : public CCommon. Dialog { public: OPENFILENAME m_ofn; // open file parameter block virtual int Do. Modal(); CString Get. Path. Name() const; // return full path and filename CString Get. File. Name() const; // return only filename CString Get. File. Ext() const; // return only ext CString Get. File. Title() const; // return file title BOOL Get. Read. Only. Pref() const; // return TRUE if readonly checked // Enumerating multiple file selections POSITION Get. Start. Position() const; CString Get. Next. Path. Name(POSITION& pos) const; 47 비트교육센터

Common Dialogs (cont’d) protected: friend UINT CALLBACK _Afx. Comm. Dlg. Proc(HWND, UINT, WPARAM, LPARAM);

Common Dialogs (cont’d) protected: friend UINT CALLBACK _Afx. Comm. Dlg. Proc(HWND, UINT, WPARAM, LPARAM); virtual UINT On. Share. Violation(LPCTSTR lpsz. Path. Name); virtual BOOL On. File. Name. OK(); virtual void On. LBSel. Changed. Notify(UINT n. IDBox, UINT i. Cur. Sel, UINT n. Code); // only called back if OFN_EXPLORER is set virtual void On. Init. Done(); virtual void On. File. Name. Change(); virtual void On. Folder. Change(); virtual void On. Type. Change(); // Implementation BOOL m_b. Open. File. Dialog; // TRUE for file open, FALSE for file save CString m_str. Filter; // filter string TCHAR m_sz. File. Title[64]; // contains file title after return TCHAR m_sz. File. Name[_MAX_PATH]; // contains full path name after return OPENFILENAME* m_pofn. Temp; virtual BOOL On. Notify(WPARAM w. Param, LPARAM l. Param, LRESULT* p. Result); 비트교육센터 }; 48

Common Dialogs (cont’d) 예제 dialog – CFile. Dialog(AFXDLGS. H) OPENFILENAME structure 여러 개의 virtual

Common Dialogs (cont’d) 예제 dialog – CFile. Dialog(AFXDLGS. H) OPENFILENAME structure 여러 개의 virtual protected 함수 기타 여러 정보 저장을 위한 변수 – CFile. Dialog의 생성(DLGFILE. CPP) 생성자의 argument들을 OPENFILENAME structure의 멤버에 setting함 (m_ofn) Window 95이상일 경우에는 OFN_EXPLORER와 OFN_ENABLEHOOK flag를 set함 – OFN_ENABLEHOOK Hook routine을 제공(_Afx. Comm. Dlg. Proc()를 m_ofn의 hook field에 set) 49 비트교육센터

Common Dialogs (cont’d) – CFile. Dialog: : Do. Modal()(DLGFILE. CPP) M_b. Open. File. Dialog변수의

Common Dialogs (cont’d) – CFile. Dialog: : Do. Modal()(DLGFILE. CPP) M_b. Open. File. Dialog변수의 값을 보고 Win 32 API인 Get. Open. File. Name()을 호출할건지 Get. Save. File. Name()을 호출할건지를 결정 50 비트교육센터

Common Dialogs (cont’d) int CFile. Dialog: : Do. Modal() { int n. Result; BOOL

Common Dialogs (cont’d) int CFile. Dialog: : Do. Modal() { int n. Result; BOOL b. Enable. Parent = FALSE; m_ofn. hwnd. Owner = Pre. Modal(); Afx. Unhook. Window. Create(); if (m_ofn. hwnd. Owner != NULL && : : Is. Window. Enabled(m_ofn. hwnd. Owner)) { b. Enable. Parent = TRUE; : : Enable. Window(m_ofn. hwnd. Owner, FALSE); } if (m_b. Open. File. Dialog) n. Result = : : Get. Open. File. Name(&m_ofn); else n. Result = : : Get. Save. File. Name(&m_ofn); if (b. Enable. Parent) : : Enable. Window(m_ofn. hwnd. Owner, TRUE); Post. Modal(); return n. Result ? n. Result : IDCANCEL; } 51 비트교육센터

Property Sheets (cont’d) 두개의 class – CProperty. Sheet 버튼역할 Tabbed dialog를 위한 class –

Property Sheets (cont’d) 두개의 class – CProperty. Sheet 버튼역할 Tabbed dialog를 위한 class – CProperty. Page 리소스와 관련 Tabbed dialog의 각각의 tab(page)을 위한 class 일반 dialog와의 차이점 – Apply버튼 제공 Page별로 update하는 기능을 제공 53 비트교육센터

Property Sheets (cont’d) STEP – 1. Dialog template 생성 및 property sheet 의 layout

Property Sheets (cont’d) STEP – 1. Dialog template 생성 및 property sheet 의 layout 설정 – 2. 각 template 에 대응하는 CProperty. Page 파생 클래스들을 생성 – 3 -1. (modal property sheet) CProperty. Sheet의 instance를 생성하고 Add. Page() 멤버 함수를 통해 추가한 뒤 Do. Modal() 호출 OK/Apply/Cancel 버튼이 자동적으로 추가 – 3 -2. (modeless property sheet) CProperty. Sheet의 파생클래스 생성한 뒤 인스턴스를 생성하고 Create() 함수 호출 OK/Apply/Cancel 버튼이 자동적으로 추가되지 않음 54 비트교육센터

Property Sheets (cont’d) CProperty. Sheet my. Sheet(“My Property Sheet!”, this); CPage. One my. Page

Property Sheets (cont’d) CProperty. Sheet my. Sheet(“My Property Sheet!”, this); CPage. One my. Page 1; CPage. Two my. Page 2; CPage. Three my. Page 3; my. Sheet. Add. Page(&my. Page 1); my. Sheet. Add. Page(&my. Page 2); my. Sheet. Add. Page(&my. Page 3); my. Sheet. Do. Modal(); … 55 비트교육센터

CProperty. Sheet Class Declaration of CProperty. Sheet – AFXDLGS. H (CWnd의 파생클래스임…) 다이얼로그의 특성을

CProperty. Sheet Class Declaration of CProperty. Sheet – AFXDLGS. H (CWnd의 파생클래스임…) 다이얼로그의 특성을 가져오기가 어 렵다는 뜻임. class CProperty. Sheet : public CWnd { // Attributes public: AFX_OLDPROPSHEETHEADER m_psh; int Get. Page. Count() const; CProperty. Page* Get. Active. Page() const; int Get. Active. Index() const; CProperty. Page* Get. Page(int n. Page) const; int Get. Page. Index(CProperty. Page* p. Page); BOOL Set. Active. Page(int n. Page); BOOL Set. Active. Page(CProperty. Page* p. Page); void Set. Title(LPCTSTR lpsz. Text, UINT n. Style = 0); void Enable. Stacked. Tabs(BOOL b. Stacked); 56 비트교육센터

CProperty. Sheet Class (cont’d) // Operations public: virtual int Do. Modal(); void Add. Page(CProperty.

CProperty. Sheet Class (cont’d) // Operations public: virtual int Do. Modal(); void Add. Page(CProperty. Page* p. Page); void Remove. Page(int n. Page); void End. Dialog(int n. End. ID); // used to terminate a modal dialog BOOL Press. Button(int n. Button); // Implementation public: virtual ~CProperty. Sheet(); void Common. Construct(CWnd* p. Parent. Wnd, UINT i. Select. Page); virtual BOOL Pre. Translate. Message(MSG* p. Msg); virtual void Build. Prop. Page. Array(); virtual BOOL On. Command(WPARAM w. Param, LPARAM l. Param); virtual BOOL On. Init. Dialog(); virtual BOOL Continue. Modal(); 57 비트교육센터

CProperty. Sheet Class (cont’d) protected: CPtr. Array m_pages; // array of CProperty. Page pointers

CProperty. Sheet Class (cont’d) protected: CPtr. Array m_pages; // array of CProperty. Page pointers CString m_str. Caption; // caption of the pseudo-dialog CWnd* m_p. Parent. Wnd; // parent window of property sheet BOOL m_b. Stacked; // Enable. Stacked. Tabs sets this BOOL m_b. Modeless; // TRUE when Create called instead of Do. Modal // Generated message map functions //{{AFX_MSG(CProperty. Sheet) afx_msg BOOL On. Nc. Create(LPCREATESTRUCT); afx_msg LRESULT Handle. Init. Dialog(WPARAM, LPARAM); afx_msg HBRUSH On. Ctl. Color(CDC* p. DC, CWnd* p. Wnd, UINT n. Ctl. Color); afx_msg LRESULT On. Command. Help(WPARAM, LPARAM); afx_msg void On. Close(); afx_msg void On. Sys. Command(UINT n. ID, LPARAM); afx_msg LRESULT On. Set. Def. ID(WPARAM, LPARAM); //}}AFX_MSG friend class CProperty. Page; }; 58 비트교육센터

CProperty. Sheet Class (cont’d) Declaration of CProperty. Sheet – AFXDLGS. H – CWnd에서 상속받음

CProperty. Sheet Class (cont’d) Declaration of CProperty. Sheet – AFXDLGS. H – CWnd에서 상속받음 (why? ) – 멤버 Common. Construct() – 수많은 constructor들이 호출하는 공통 함수 m_pages – CPtr. Array형의 pointer로 CProperty. Page class의 pointer의 배열 59 비트교육센터

CProperty. Sheet Class (cont’d) m_str. Caption – Property sheet의 caption m_p. Parent. Wnd –

CProperty. Sheet Class (cont’d) m_str. Caption – Property sheet의 caption m_p. Parent. Wnd – Parent window에 대한 pointer m_b. Stacked – Tab을 stacked mode로 할건지 scrolled mode로 할 건지를 결정 m_b. Modeless – Property sheet를 modal로 할건지 modeless로 할건지 60 비트교육센터

CProperty. Sheet Class (cont’d) CProperty. Sheet: : Do. Modal() – DLGPROP. CPP – 내부

CProperty. Sheet Class (cont’d) CProperty. Sheet: : Do. Modal() – DLGPROP. CPP – 내부 수행 Afx. Defer. Register. Class()호출 – 내부적으로 Init. Common. Controls()함수 호출(Windows common controls DLL을 초기화) Build. Prop. Page. Array()호출 Main window를 disable하고 : : Property. Sheet()함수를 호출 (이후는 CDialog: : Do. Modal()과 동일) 61 비트교육센터

CProperty. Sheet Class (cont’d) CProperty. Sheet: : Add. Page() – DLGPROP. CPP – m_pages멤버

CProperty. Sheet Class (cont’d) CProperty. Sheet: : Add. Page() – DLGPROP. CPP – m_pages멤버 변수에 page 추가 CProperty. Sheet: : Build. Prop. Page. Array() – DLGPROP. CPP – 각 page에 있는 PROPSHEETPAGE structure정보를 저장함 62 비트교육센터

CProperty. Sheet Class (cont’d) int CProperty. Sheet: : Do. Modal() { VERIFY(Afx. Defer. Register.

CProperty. Sheet Class (cont’d) int CProperty. Sheet: : Do. Modal() { VERIFY(Afx. Defer. Register. Class(AFX_WNDCOMMCTLS_REG)); Build. Prop. Page. Array(); HWND h. Wnd. Parent = CWnd: : Get. Safe. Owner_(); : : Enable. Window(h. Wnd. Parent, FALSE); HWND h. Wnd = (HWND): : Property. Sheet((PROPSHEETHEADER*)psh); n. Result = Run. Modal. Loop(dw. Flags); Destroy. Window(); : : Enable. Window(h. Wnd. Top, TRUE); return n. Result; } 63 비트교육센터

CProperty. Sheet Class (cont’d) void CProperty. Sheet: : Add. Page(CProperty. Page* p. Page) {

CProperty. Sheet Class (cont’d) void CProperty. Sheet: : Add. Page(CProperty. Page* p. Page) { m_pages. Add(p. Page); if (m_h. Wnd != NULL) { HPROPSHEETPAGE h. PSP = Create. Property. Sheet. Page((PROPSHEETPAGE*)ppsp); if (h. PSP == NULL) Afx. Throw. Memory. Exception(); if (!Send. Message(PSM_ADDPAGE, 0, (LPARAM)h. PSP)) { Destroy. Property. Sheet. Page(h. PSP); Afx. Throw. Memory. Exception(); } } } 64 비트교육센터

CProperty. Sheet Class (cont’d) void CProperty. Sheet: : Build. Prop. Page. Array() { delete[]

CProperty. Sheet Class (cont’d) void CProperty. Sheet: : Build. Prop. Page. Array() { delete[] (PROPSHEETPAGE*)m_psh. ppsp; m_psh. ppsp = NULL; AFX_OLDPROPSHEETPAGE* ppsp = new AFX_OLDPROPSHEETPAGE[m_pages. Get. Size()]; m_psh. ppsp = (LPPROPSHEETPAGE)ppsp; for (int i = 0; i < m_pages. Get. Size(); i++) { CProperty. Page* p. Page = Get. Page(i); memcpy(&ppsp[i], &p. Page->m_psp, sizeof(p. Page->m_psp)); p. Page->Pre. Process. Page. Template ((PROPSHEETPAGE&)ppsp[i], b. Wizard); } m_psh. n. Pages = m_pages. Get. Size(); } 65 비트교육센터

Control Classes Control class의 세가지 group – Old fashioned (6) Button, combo box, edit,

Control Classes Control class의 세가지 group – Old fashioned (6) Button, combo box, edit, list box, scroll bar, static – New fangled Window common controls – OLE controls 66 비트교육센터

Old-Fashioned 특징 – 모두 CWnd에서 상속받음 – Cbitmap, CBitmap. Button, CCombo. Box, CEdit, CList.

Old-Fashioned 특징 – 모두 CWnd에서 상속받음 – Cbitmap, CBitmap. Button, CCombo. Box, CEdit, CList. Box, CDrag. List. Box, CCheck. List. Box, CScroll. Bar, CStatic – Declaration은 AFXWIN. H – Implementation AFXWIN 2. INL WINCTRL 1. CPP WINCTRL 2. CPP WINCTRL 3. CPP WINBTN. CPP 67 비트교육센터

Old-Fashioned (cont’d) Cbutton* p. Button = (Cbutton *)p. Dialog->Get. Dlg. Item(IDC_CHECK 1); ASSERT(p. Button

Old-Fashioned (cont’d) Cbutton* p. Button = (Cbutton *)p. Dialog->Get. Dlg. Item(IDC_CHECK 1); ASSERT(p. Button != NULL); p. Button->Set. Check(m_b. Show. State); //// Crect. Button(10, 50, 50); Cbutton* p. Button = new Cbutton; p. Button->Create(“Text”, WS_CHILD|BS_PUSHBUTTON, rect. Button, p. View, ID_BUTTON); … p. Btton->Destroy. Window(); delete p. Button; 68 비트교육센터

New-fangled 특징 – 모두 CWnd에서 상속받음 – CAnimate. Ctrl, CDrag. List. Box, CHot. Key.

New-fangled 특징 – 모두 CWnd에서 상속받음 – CAnimate. Ctrl, CDrag. List. Box, CHot. Key. Ctrl, CImage. List, CProgress. Ctrl, CRich. Edit. Ctrl, CSlider. Ctrl, CSpin. Button. Ctrl, … – Declaration은 AFXCMN. H – Implementation AFXCMN. INL WINCTRL 2. CPP WINCTRL 4. CPP 69 비트교육센터

Chapter 07 MFC 의 Document View Arhitecture

Chapter 07 MFC 의 Document View Arhitecture

Contents Introduction Architecture Inside document/view architecture Document/view internals 71 비트교육센터

Contents Introduction Architecture Inside document/view architecture Document/view internals 71 비트교육센터

Introduction Application의 data관리 – Data를 분리하여 관리하자. – 중요한 이슈 누가 data를 관리할 것인가

Introduction Application의 data관리 – Data를 분리하여 관리하자. – 중요한 이슈 누가 data를 관리할 것인가 누가 data를 update할 것인가 data 의 rendering 어떻게 다르게 할 것인가 … – Print 와 print preview의 지원 – 두 부분 Data management(Document) User-interface management(Frame/View) 72 비트교육센터

Introduction (cont’d) 기존의 방법 – 분리하지 않고 하나의 클래스에서 처리 – 대단히 복잡 중요성

Introduction (cont’d) 기존의 방법 – 분리하지 않고 하나의 클래스에서 처리 – 대단히 복잡 중요성 – Multiple ways to represent your data Rendering & Updating – Multiple types of data User interface 73 비트교육센터

Architecture Document와 view – Document Application의 data를 의미 – View Application의 data의 표현을 의미

Architecture Document와 view – Document Application의 data를 의미 – View Application의 data의 표현을 의미 74 비트교육센터

Document/View Components MFC document/view architecture를 위한 4개의 components – – Documents Views Document/view frames

Document/View Components MFC document/view architecture를 위한 4개의 components – – Documents Views Document/view frames Document templates 75 비트교육센터

Document/View Components(cont’d) Documents – CDocument class Managing file I/O Updating renderings of the data

Document/View Components(cont’d) Documents – CDocument class Managing file I/O Updating renderings of the data CCmd. Target(CObject)로 부터 상속 받음 – CObject Run-time type information, dynamic creation, serialization – CCmd. Target Command message (WM_COMMAND)를 받을 수 있 음 76 비트교육센터

Document/View Components(cont’d) Views – CView class CWnd(CCmd. Target, CObject)로 부터 상속 받음 – CCmd.

Document/View Components(cont’d) Views – CView class CWnd(CCmd. Target, CObject)로 부터 상속 받음 – CCmd. Target Command message (WM_COMMAND)를 받을 수 있 음 – CWnd Window message(WM_PAINT)를 받을 수 있음 View는 border가 없는 window임 View를 둘러싸고 있는 border있는 window를 frame window라고 함 77 비트교육센터

Document/View Components(cont’d) Document/View Frames – 각각의 view에 서로 다른 user-interface를 적용할 수 있게 함

Document/View Components(cont’d) Document/View Frames – 각각의 view에 서로 다른 user-interface를 적용할 수 있게 함 Frame View 78 비트교육센터

Document/View Components(cont’d) – SDI CFrame. Wnd class Single Document Interface 워드패드 – MDI CMDIChild.

Document/View Components(cont’d) – SDI CFrame. Wnd class Single Document Interface 워드패드 – MDI CMDIChild. Wnd class Multiple Document Inteface MS Word 79 비트교육센터

Document/View Components(cont’d) Document templates – – CDoc. Template class Document, view, frame을 묶어서 하나의

Document/View Components(cont’d) Document templates – – CDoc. Template class Document, view, frame을 묶어서 하나의 unit으로 관리 각각의 서로 다른 document type에 대하여 하나씩의 template을 가질 수 있다. 실제 사용시 한 type의 document CSingle. Doc. Template class 여러 type의 document CMulti. Doc. Template class 80 비트교육센터

Document/View Components(cont’d) CSingle. Doc. Template – 생성자의 인자 Resource ID Documet/View/Frame 의 Run-time class

Document/View Components(cont’d) CSingle. Doc. Template – 생성자의 인자 Resource ID Documet/View/Frame 의 Run-time class CMulti. Doc. Template – CSingle. Doc. Template와 생성자의 인자가 동일 – 차이점 : linked list를 통해 다수의 정보 유지 81 비트교육센터

Document/View Components(cont’d) Resource ID – – – application 의 string table window title, document

Document/View Components(cont’d) Resource ID – – – application 의 string table window title, document name 새 document 생성 시 description 파일 open 시 파일 type 에 대한 description file extension filter, … 82 비트교육센터

CWin. App의 역할 (cont’d) BOOL CTest. App: : Init. Instance() { … CMulti. Doc.

CWin. App의 역할 (cont’d) BOOL CTest. App: : Init. Instance() { … CMulti. Doc. Template* p. Doc. Template; p. Doc. Template = new CMulti. Doc. Template( IDR_TESTTYPE, RUNTIME_CLASS(CTest. Doc), RUNTIME_CLASS(CChild. Frame), // custom MDI child frame RUNTIME_CLASS(CTest. View)); Add. Doc. Template(p. Doc. Template); 리스트로 넣어주는부분 … } 84 비트교육센터

Document/View Arch. Internals Document/View arch. 의 기본 – CWin. App Document template의 관리 –

Document/View Arch. Internals Document/View arch. 의 기본 – CWin. App Document template의 관리 – Document template Frames/Views/Documents의 관리 85 비트교육센터

CDoc. Manager Class CDoc. Manager – CWin. App와 CDoc. Template사이의 interface역할 – CWin. App가

CDoc. Manager Class CDoc. Manager – CWin. App와 CDoc. Template사이의 interface역할 – CWin. App가 필요한 document template의 list를 관리하는 역할 – CWin. App의 declaration(AFXWIN. H) CDoc. Manager * m_p. Doc. Manager; 이 객체가 관리한다. 86 비트교육센터

CDoc. Manager Class(contd. ) class CDoc. Manager : public CObject { DECLARE_DYNAMIC(CDoc. Manager) CDoc.

CDoc. Manager Class(contd. ) class CDoc. Manager : public CObject { DECLARE_DYNAMIC(CDoc. Manager) CDoc. Manager(); virtual void Add. Doc. Template(CDoc. Template* p. Template); virtual POSITION Get. First. Doc. Template. Position() const; virtual CDoc. Template* Get. Next. Doc. Template(POSITION& pos) const; virtual void Register. Shell. File. Types(BOOL b. Compat); void Unregister. Shell. File. Types(); virtual CDocument* Open. Document. File(LPCTSTR lpsz. File. Name); virtual BOOL Save. All. Modified(); // save before exit virtual void Close. All. Documents(BOOL b. End. Session); virtual int Get. Open. Document. Count(); CPtr. List m_template. List; int Get. Document. Count(); }; 87 비트교육센터

CDoc. Manager Class(contd. ) Declaration(AFXWIN. H) – 멤버 변수 m_template. List – CPtr. List

CDoc. Manager Class(contd. ) Declaration(AFXWIN. H) – 멤버 변수 m_template. List – CPtr. List type – 실제 document template의 list – 멤버 함수 대부분의 함수가 m_template. List에 대한 조작과 CWin. App와의 interface를 위 해서 존재 88 비트교육센터

CDoc. Manager Class(contd. ) 대부분의 CWin. App의 document template관련 함수는 CDoc. Manager의 함수 를

CDoc. Manager Class(contd. ) 대부분의 CWin. App의 document template관련 함수는 CDoc. Manager의 함수 를 그대로 호출함 – CWin. App: : Add. Doc. Template() – CWin. App: : Close. All. Document() – CWin. App: : Do. Prompt. File. Name() – CWin. App: : Get. First. Doc. Template. Position() – CWin. App: : Get. Next. Doc. Template() – CWin. App: : Get. Open. Document. Count() – CWin. App: : On. File. New() – CWin. App: : On. File. Open() – … 89 비트교육센터

CDoc. Manager Class(contd. ) void CWin. App: : Add. Doc. Template(CDoc. Template* p. Template)

CDoc. Manager Class(contd. ) void CWin. App: : Add. Doc. Template(CDoc. Template* p. Template) { if (m_p. Doc. Manager == NULL) m_p. Doc. Manager = new CDoc. Manager; m_p. Doc. Manager->Add. Doc. Template(p. Template); } void CWin. App: : On. File. New() { if (m_p. Doc. Manager != NULL) m_p. Doc. Manager->On. File. New(); } 90 비트교육센터

CDoc. Manager Class(contd. ) CDoc. Manager: : On. File. New() – 새로운 document template을

CDoc. Manager Class(contd. ) CDoc. Manager: : On. File. New() – 새로운 document template을 생성하는 역할 – 하나 이상의 document template가 있을때는 CNew. Type. Dlg dialog class를 이 용(DOCMGR. CPP) 사용자가 document template을 선택하게 함 사용자에게 document template list로 보여주는 좋은 예가 됨 91 비트교육센터

CDoc. Manager Class(contd. ) “Doc. Mgr. cpp” void CDoc. Manager: : On. File. New()

CDoc. Manager Class(contd. ) “Doc. Mgr. cpp” void CDoc. Manager: : On. File. New() { CDoc. Template* p. Template = (CDoc. Template*)m_template. List. Get. Head(); if (m_template. List. Get. Count() > 1) { CNew. Type. Dlg dlg(&m_template. List); 열고자하는탬플릿이 선택됨 int n. ID = dlg. Do. Modal(); if (n. ID == IDOK) p. Template = dlg. m_p. Selected. Template; else return; // none - cancel operation } p. Template->Open. Document. File(NULL); } 92 비트교육센터

CDoc. Manager Class(contd. ) CNew. Type. Dlg class – DOCMGR. CPP class CNew. Type.

CDoc. Manager Class(contd. ) CNew. Type. Dlg class – DOCMGR. CPP class CNew. Type. Dlg : public CDialog { protected: CPtr. List* m_p. List; // actually a list of doc templates public: CDoc. Template* m_p. Selected. Template; //사용자가 선택한 탬플릿 enum { IDD = AFX_IDD_NEWTYPEDLG }; CNew. Type. Dlg(CPtr. List* p. List) : CDialog(CNew. Type. Dlg: : IDD) { m_p. List = p. List; m_p. Selected. Template = NULL; } protected: BOOL On. Init. Dialog(); void On. OK(); }; 93 비트교육센터

CDoc. Manager Class(contd. ) CNew. Type. Dlg resource – AFXRES. RC 94 비트교육센터

CDoc. Manager Class(contd. ) CNew. Type. Dlg resource – AFXRES. RC 94 비트교육센터

CDoc. Manager Class(contd. ) BOOL CNew. Type. Dlg: : On. Init. Dialog() { CList.

CDoc. Manager Class(contd. ) BOOL CNew. Type. Dlg: : On. Init. Dialog() { CList. Box* p. List. Box = (CList. Box*)Get. Dlg. Item(AFX_IDC_LISTBOX); POSITION pos = m_p. List->Get. Head. Position(); while (pos != NULL) { CDoc. Template* p. Template = (CDoc. Template*)m_p. List->Get. Next(pos); CString str. Type. Name; if (p. Template->Get. Doc. String(str. Type. Name, CDoc. Template: : file. New. Name) && !str. Type. Name. Is. Empty()) { int n. Index = p. List. Box->Add. String(str. Type. Name); p. List. Box->Set. Item. Data. Ptr(n. Index, p. Template); } } return CDialog: : On. Init. Dialog(); } 95 비트교육센터

CDoc. Template class CDoc. Template – Document/View/Frame을 관리 – Base class – 실제 사용시에는

CDoc. Template class CDoc. Template – Document/View/Frame을 관리 – Base class – 실제 사용시에는 둘중하나의 파생클래스를 사용 CSingle. Doc. Template – DOCSINGL. CPP CMulti. Doc. Template – DOCMULTI. CPP 96 비트교육센터

CDoc. Template class(contd. ) Declaration(AFXWIN. H) class CDoc. Template : public CCmd. Target {

CDoc. Template class(contd. ) Declaration(AFXWIN. H) class CDoc. Template : public CCmd. Target { DECLARE_DYNAMIC(CDoc. Template) protected: CDoc. Template(UINT n. IDResource, CRuntime. Class* p. Doc. Class, CRuntime. Class* p. Frame. Class, CRuntime. Class* p. View. Class); // Attributes public: virtual POSITION Get. First. Doc. Position() const = 0; virtual CDocument* Get. Next. Doc(POSITION& r. Pos) const = 0; virtual void Add. Document(CDocument* p. Doc); // must override virtual void Remove. Document(CDocument* p. Doc); // must override virtual BOOL Get. Doc. String(CString& r. String, enum Doc. String. Index index) const; // get one of the info strings CFrame. Wnd* Create. Ole. Frame(CWnd* p. Parent. Wnd, CDocument* p. Doc, BOOL b. Create. View); virtual CDocument* Create. New. Document(); virtual CFrame. Wnd* Create. New. Frame(CDocument* p. Doc, CFrame. Wnd* p. Other); 97 비트교육센터

CDoc. Template class(contd. ) virtual void Initial. Update. Frame(CFrame. Wnd* p. Frame, CDocument* p.

CDoc. Template class(contd. ) virtual void Initial. Update. Frame(CFrame. Wnd* p. Frame, CDocument* p. Doc, BOOL b. Make. Visible = TRUE); virtual BOOL Save. All. Modified(); // for all documents virtual void Close. All. Documents(BOOL b. End. Session); virtual CDocument* Open. Document. File( LPCTSTR lpsz. Path. Name, BOOL b. Make. Visible = TRUE) = 0; virtual void Set. Default. Title(CDocument* p. Document) = 0; public: BOOL m_b. Auto. Delete; virtual ~CDoc. Template(); protected: UINT m_n. IDResource; CRuntime. Class* m_p. Doc. Class; // class for creating new documents CRuntime. Class* m_p. Frame. Class; // class for creating new frames CRuntime. Class* m_p. View. Class; // class for creating new views CString m_str. Doc. Strings; // 'n' separated names }; 98 비트교육센터

CDoc. Template class(contd. ) Declaration(AFXWIN. H) – 멤버 변수 m_n. IDResource – Document template에

CDoc. Template class(contd. ) Declaration(AFXWIN. H) – 멤버 변수 m_n. IDResource – Document template에 대한 resource ID m_p. Doc. Class – CDocument에 대한 CRuntime. Class structure의 pointer m_p. Frame. Class – CFrame. Wnd에 대한 CRuntime. Class structure의 pointer 99 비트교육센터

CDoc. Template class(contd. ) m_p. View. Class – CView에 대한 CRuntime. Class structure의 pointer

CDoc. Template class(contd. ) m_p. View. Class – CView에 대한 CRuntime. Class structure의 pointer m_str. Doc. Strings – Document template의 string resource Implementation(DOCTEMPL. CPP) – Document/View/Frame을 생성하는 함수 CDoc. Template: : Create. New. Document() CDoc. Template: : Create. New. Frame() View에 관한 명시적인 함수는 없음 100 비트교육센터

CDoc. Template class(contd. ) CDocument* CDoc. Template: : Create. New. Document() { CDocument* p.

CDoc. Template class(contd. ) CDocument* CDoc. Template: : Create. New. Document() { CDocument* p. Document = (CDocument*)m_p. Doc. Class->Create. Object(); Add. Document(p. Document); //생성될 때 바로 연결리스트에 넣어준다. return p. Document; } 101 비트교육센터

CDoc. Template class(contd. ) CFrame. Wnd* CDoc. Template: : Create. New. Frame(CDocument* p. Doc,

CDoc. Template class(contd. ) CFrame. Wnd* CDoc. Template: : Create. New. Frame(CDocument* p. Doc, CFrame. Wnd* p. Other) { CCreate. Context context; context. m_p. Current. Frame = p. Other; context. m_p. Current. Doc = p. Doc; context. m_p. New. View. Class = m_p. View. Class; context. m_p. New. Doc. Template = this; View의 생성에 필요한 정보들을 저장한다. (4가지…) CFrame. Wnd* p. Frame = (CFrame. Wnd*)m_p. Frame. Class->Create. Object(); p. Frame->Load. Frame(m_n. IDResource, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context)) return p. Frame; } 102 비트교육센터

CDoc. Template class(contd. ) – CDoc. Template: : Create. New. Document() m_p. Doc. Class->Create.

CDoc. Template class(contd. ) – CDoc. Template: : Create. New. Document() m_p. Doc. Class->Create. Object()를 이용해 document생성 생성된 document를 open된 document list에 추가 – CDoc. Template: : Create. New. Frame() CCreate. Context에 필요한 정보를 채움 m_p. Frame. Class->Create. Object()를 이용해 frame생성 Frame에 필요한 resource를 load 103 비트교육센터

CDoc. Template class(contd. ) – CCreate. Context structure Declaration(AFXEXT. H) struct CCreate. Context //

CDoc. Template class(contd. ) – CCreate. Context structure Declaration(AFXEXT. H) struct CCreate. Context // Creation information structure // All fields are optional and may be NULL { CRuntime. Class* m_p. New. View. Class; CDocument* m_p. Current. Doc; // for creating MDI children (CMDIChild. Wnd: : Load. Frame) CDoc. Template* m_p. New. Doc. Template; // for sharing view/frame state from the original view/frame CView* m_p. Last. View; CFrame. Wnd* m_p. Current. Frame; // Implementation CCreate. Context(); }; 104 비트교육센터

CDoc. Template class(contd. ) – CCreate. Context structure Declaration(AFXEXT. H) – m_p. New. View.

CDoc. Template class(contd. ) – CCreate. Context structure Declaration(AFXEXT. H) – m_p. New. View. Class View생성을 위한 CRuntime. Class pointer – m_p. Current. Doc Current document – m_p. Current. Frame Current frame – m_p. New. Doc. Template Multiple document 일 때 마지막 document 를 가리킴 – m_p. Last. View Multiple view일 때 마지막 view를 가리킴 105 비트교육센터

CDoc. Template class(contd. ) Open된 document의 관리는? – CSingle. Doc. Template와 CMulti. Doc. Template가

CDoc. Template class(contd. ) Open된 document의 관리는? – CSingle. Doc. Template와 CMulti. Doc. Template가 담당 CSingle. Doc. Template(하나만 저장되면 됨 포인터변수하나면충분) – CDocument* m_p. Only. Doc; CMulti. Doc. Template(여러개저장필요 Linked. List사용) – CPtr. List m_doc. List; – int m_n. Untitled. Count; Untitled document의 수를 저장함(Untitled[X]) 106 비트교육센터

CDoc. Template class(contd. ) – CMulti. Doc. Template: : Open. Document. File() DOCMULTI. CPP

CDoc. Template class(contd. ) – CMulti. Doc. Template: : Open. Document. File() DOCMULTI. CPP Document와 frame의 생성 CFrame. Wnd: : Initial. Update. Frame()호출 107 비트교육센터

CDoc. Template class(contd. ) “Doc. Multi. cpp” CDocument* CMulti. Doc. Template: : Open. Document.

CDoc. Template class(contd. ) “Doc. Multi. cpp” CDocument* CMulti. Doc. Template: : Open. Document. File(LPCTSTR lpsz. Path. Name, BOOL b. Make. Visible) { CDocument* p. Document = Create. New. Document(); CFrame. Wnd* p. Frame = Create. New. Frame(p. Document, NULL); if (lpsz. Path. Name == NULL) {(새로운 파일을 생성하는 경우) // create a new document - with default document name Set. Default. Title(p. Document); p. Document->On. New. Document(); } else { // open an existing document(기존의 파일을 오픈하는 경우) CWait. Cursor wait; p. Document->On. Open. Document(lpsz. Path. Name); p. Document->Set. Path. Name(lpsz. Path. Name); } return p. Document; 비트교육센터 } 108

CFrame. Wnd class CFrame. Wnd – CView의 생성! – m_p. View. Active 현재 atcive한

CFrame. Wnd class CFrame. Wnd – CView의 생성! – m_p. View. Active 현재 atcive한 view에 대한 pointer CFrame. Wnd: : Get. Active. View() CFrame. Wnd: : Set. Active. View() – Initial. Update. Frame()함수 모든 view의 On. Initial. Update()함수를 호출함 109 비트교육센터

CFrame. Wnd class(contd. ) Implementation(WINFRM. CPP) – CFrame. Wnd: : Create. View() 진정한 view의

CFrame. Wnd class(contd. ) Implementation(WINFRM. CPP) – CFrame. Wnd: : Create. View() 진정한 view의 생성 CWnd* CFrame. Wnd: : Create. View(CCreate. Context* p. Context, UINT n. ID) { CWnd* p. View = (CWnd*)p. Context->m_p. New. View. Class ->Create. Object(); if (p. View == NULL) return NULL; if (!p. View->Create(NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, n. ID, p. Context)) return NULL; // can't continue without a view return p. View; } Frame윈도우가 부모윈도우, View윈도우가 자식윈도우가 될것이라는 것을 암시 110 비트교육센터

CFrame. Wnd class(contd. ) 그러면 Create. View()는 어디서 호출되나? int CFrame. Wnd: : On.

CFrame. Wnd class(contd. ) 그러면 Create. View()는 어디서 호출되나? int CFrame. Wnd: : On. Create(LPCREATESTRUCT lpcs) { return On. Create. Helper(lpcs, p. Context); } int CFrame. Wnd: : On. Create. Helper(LPCREATESTRUCT lpcs, CCreate. Context* p. Context) { if (CWnd: : On. Create(lpcs) == -1) return -1; // create special children first On. Create. Client(lpcs, p. Context); } 111 비트교육센터

CFrame. Wnd class(contd. ) 여기서 Create. View가 호출된다. BOOL CFrame. Wnd: : On. Create.

CFrame. Wnd class(contd. ) 여기서 Create. View가 호출된다. BOOL CFrame. Wnd: : On. Create. Client(LPCREATESTRUCT, CCreate. Context* p. Context) { if (p. Context != NULL && p. Context->m_p. New. View. Class != NULL) { Create. View(p. Context, AFX_IDW_PANE_FIRST); } } 여기부분을 수정하게 되면 다중의 View 도 구현이 된다. 112 비트교육센터

CFrame. Wnd class(contd. ) Create. New. Frame()이 호출되면 – Windows가 WM_CREATE message를 보냄 –

CFrame. Wnd class(contd. ) Create. New. Frame()이 호출되면 – Windows가 WM_CREATE message를 보냄 – On. Create()함수의 호출 – On. Create. Helper()의 호출 – On. Create. Client()의 호출 – Create. View()의 호출 결국 Create. New. Frame()의 호출 결과임 113 비트교육센터

CFrame. Wnd class(contd. ) CFrame. Wnd: : Initial. Update. Frame() – Frame의 모든 view를

CFrame. Wnd class(contd. ) CFrame. Wnd: : Initial. Update. Frame() – Frame의 모든 view를 update함 void CFrame. Wnd: : Initial. Update. Frame(CDocument* p. Doc, BOOL b. Make. Visible) { CView* p. View = NULL; if (b. Make. Visible) { Send. Message. To. Descendants(WM_INITIALUPDATE, 0, 0, TRUE); Activate. Frame(n. Cmd. Show); if (p. View != NULL) p. View->On. Activate. View(TRUE, p. View); } // update frame counts and frame title (may already have been visible) if (p. Doc != NULL) p. Doc->Update. Frame. Counts(); On. Update. Frame. Title(TRUE); } 비트교육센터 114

CDocument Class CDocument – Declaration(AFXWIN. H) class CDocument : public CCmd. Target { public:

CDocument Class CDocument – Declaration(AFXWIN. H) class CDocument : public CCmd. Target { public: const CString& Get. Title() const; virtual void Set. Title(LPCTSTR lpsz. Title); const CString& Get. Path. Name() const; virtual void Set. Path. Name(LPCTSTR lpsz. Path. Name, BOOL b. Add. To. MRU = TRUE); virtual BOOL Is. Modified(); virtual void Set. Modified. Flag(BOOL b. Modified = TRUE); virtual POSITION Get. First. View. Position() const; virtual CView* Get. Next. View(POSITION& r. Position) const; void Update. All. Views(CView* p. Sender, LPARAM l. Hint = 0 L, CObject* p. Hint = NULL); virtual void Delete. Contents(); // 115 delete doc items etc 비트교육센터

CDocument Class (cont’d) // File helpers virtual BOOL On. New. Document(); virtual BOOL On.

CDocument Class (cont’d) // File helpers virtual BOOL On. New. Document(); virtual BOOL On. Open. Document(LPCTSTR lpsz. Path. Name); virtual CFile* Get. File(LPCTSTR lpsz. File. Name, UINT n. Open. Flags, …); virtual void Release. File(CFile* p. File, BOOL b. Abort); protected: CString m_str. Title; CString m_str. Path. Name; CDoc. Template* m_p. Doc. Template; CPtr. List m_view. List; // list of views BOOL m_b. Modified; // changed since last saved virtual BOOL Do. Save(LPCTSTR lpsz. Path. Name, BOOL b. Replace = TRUE); virtual BOOL Do. File. Save(); virtual void Update. Frame. Counts(); void Disconnect. Views(); void Send. Initial. Update(); friend class CDoc. Template; 비트교육센터 }; 116

CDocument Class (cont’d) Implementation(DOCCORE. CPP) Key aspects – Creating documents – Saving documents –

CDocument Class (cont’d) Implementation(DOCCORE. CPP) Key aspects – Creating documents – Saving documents – Communicating with views 117 비트교육센터

CDocument Class (cont’d) Creating Documents – Empty document일 경우 On. New. Document()함수 호출 –

CDocument Class (cont’d) Creating Documents – Empty document일 경우 On. New. Document()함수 호출 – Delete. Contents()호출 – Modified flag를 FALSE로 함 – m_str. Path. Name이 NULL인지 확인 – File로 부터 create하는 경우 On. Open. Document()함수 호출 – Get. File()함수를 이용하여 file open – Delete. Contents()함수 호출 – Modified flag를 TRUE로 함 – CArchive class를 이용하여 serialization – Modified flag를 FALSE로 함 118 비트교육센터

CDocument Class (cont’d) BOOL CDocument: : On. New. Document() { if (Is. Modified()) TRACE

CDocument Class (cont’d) BOOL CDocument: : On. New. Document() { if (Is. Modified()) TRACE 0("Warning: On. New. Document replaces an unsaved document. n"); Delete. Contents(); m_str. Path. Name. Empty(); Set. Modified. Flag(FALSE); // no path name yet // make clean return TRUE; } 119 비트교육센터

CDocument Class (cont’d) BOOL CDocument: : On. Open. Document(LPCTSTR lpsz. Path. Name) { CFile.

CDocument Class (cont’d) BOOL CDocument: : On. Open. Document(LPCTSTR lpsz. Path. Name) { CFile. Exception fe; CFile* p. File = Get. File(lpsz. Path. Name, CFile: : mode. Read|CFile: : share. Deny. Write, &fe); Delete. Contents(); Set. Modified. Flag(); // dirty during de-serialize CArchive load. Archive(p. File, CArchive: : load | CArchive: : b. No. Flush. On. Delete); load. Archive. m_p. Document = this; load. Archive. m_b. Force. Flat = FALSE; CWait. Cursor wait; if (p. File->Get. Length() != 0) Serialize(load. Archive); // load me load. Archive. Close(); Release. File(p. File, FALSE); Set. Modified. Flag(FALSE); // start off with unmodified return TRUE; } 비트교육센터 120

CDocument Class (cont’d) Saving Documents – On. Save. Document() Get. File()함수를 이용하여 file open

CDocument Class (cont’d) Saving Documents – On. Save. Document() Get. File()함수를 이용하여 file open CArchive class를 이용하여 serialization Modified flag를 FALSE로 함 121 비트교육센터

CDocument Class (cont’d) BOOL CDocument: : On. Save. Document(LPCTSTR lpsz. Path. Name) { CFile.

CDocument Class (cont’d) BOOL CDocument: : On. Save. Document(LPCTSTR lpsz. Path. Name) { CFile. Exception fe; CFile* p. File = NULL; p. File = Get. File(lpsz. Path. Name, CFile: : mode. Create | CFile: : mode. Read. Write | CFile: : share. Exclusive, &fe); CArchive save. Archive(p. File, CArchive: : store | CArchive: : b. No. Flush. On. Delete); save. Archive. m_p. Document = this; save. Archive. m_b. Force. Flat = FALSE; CWait. Cursor wait; Serialize(save. Archive); // save me save. Archive. Close(); Release. File(p. File, FALSE); Set. Modified. Flag(FALSE); // back to unmodified return TRUE; // success } 122 비트교육센터

CDocument Class (cont’d) void CDocument: : Update. All. Views(CView* p. Sender, LPARAM l. Hint,

CDocument Class (cont’d) void CDocument: : Update. All. Views(CView* p. Sender, LPARAM l. Hint, CObject* p. Hint) // walk through all views { ASSERT(p. Sender == NULL || !m_view. List. Is. Empty()); // must have views if sent by one of them POSITION pos = Get. First. View. Position(); //view의 포지션을 가져오고 while (pos != NULL) { CView* p. View = Get. Next. View(pos); //각각의 View포인터 ASSERT_VALID(p. View); if (p. View != p. Sender) p. View->On. Update(p. Sender, l. Hint, p. Hint); } } 124 비트교육센터

CView Class CView – Declaration(AFXWIN. H) – Implementation(VIEWCORE. CPP) void CView: : On. Paint()

CView Class CView – Declaration(AFXWIN. H) – Implementation(VIEWCORE. CPP) void CView: : On. Paint() { // standard paint routine CPaint. DC dc(this); On. Prepare. DC(&dc); On. Draw(&dc); } 125 비트교육센터

Document/View Internals CWin. App: : On. File. Open() CWin. App: : On. File. New()

Document/View Internals CWin. App: : On. File. Open() CWin. App: : On. File. New() CDoc. Manager: : On. File. Open() CDoc. Manager: : On. File. New() CDoc. Template: : Open. Document. File() CDoc. Template: : Create. New. Document() CDoc. Template: : Create. New. Frame() WM_CREATE 126 비트교육센터

Document/View…(contd. ) WM_CREATE CFrame. Wnd: : On. Create() CFrame. Wnd: : On. Create. Helper()

Document/View…(contd. ) WM_CREATE CFrame. Wnd: : On. Create() CFrame. Wnd: : On. Create. Helper() CFrame. Wnd: : On. Create. Client() CFrame. Wnd: : Create. View() CMy. Document: : On. Open. Document() CMy. Document: : On. New. Document() 127 비트교육센터