2009. 8. 27. 15:37
Programming/MFC
Resource Editor
- DDX
- IDC_GRADE : m_nGrade : Value : int
- IDC_NAME : m_strName : Value : CString
CStudent
CStudent.h
#pragma once class CStudent { public: CString m_strName; int m_nGrade; CStudent(void); CStudent(const char *szName, long nGrade); CStudent(const CStudent& s); const CStudent& operator=(const CStudent& s); BOOL operator==(const CStudent& s); BOOL operator!=(const CStudent& s); BOOL isNull(); ~CStudent(void); };
CStudnet.cpp
#include "StdAfx.h" #include ".\student.h" CStudent::CStudent(void) { m_nGrade = 0; m_strName = _T(""); } CStudent::CStudent(const char *szName, long nGrade) { m_nGrade = nGrade; m_strName = szName; } CStudent::CStudent(const CStudent& s) { m_strName = s.m_strName; m_nGrade = s.m_nGrade; } const CStudent& CStudent::operator=(const CStudent& s) { m_strName = s.m_strName; m_nGrade = s.m_nGrade; return *this; } BOOL CStudent::operator==(const CStudent& s) { if ((m_strName == s.m_strName) && (m_nGrade == s.m_nGrade)) return TRUE; else return FALSE; } BOOL CStudent::operator!=(const CStudent& s) { return !(*this == s); } BOOL CStudent::isNull() { return (*this == CStudent()); } CStudent::~CStudent(void) { }
IDC_ENTER 처리
Document 클래스
#include "Student.h" class CDocViewEx1Doc : public CDocument { // ~~~~ CStudent m_Student;
CDocViewEx1View::OnBnClickedEnter
void CDocViewEx1View::OnBnClickedEnter() { UpdateData(TRUE); CDocViewEx1Doc *pDoc = GetDocument(); pDoc->m_Student.m_nGrade = m_nGrade; pDoc->m_Student.m_strName = m_strName; }
Menu 생성
- 메뉴 : ID_DOCUMENT_MODIFY, ID_DOCUMENT_CLEAR
Menu 처리 함수
void CDocViewEx1Doc::OnDocumentClear() { m_Student = CStudent(); UpdateAllViews(NULL); } void CDocViewEx1Doc::OnUpdateDocumentClear(CCmdUI *pCmdUI) { pCmdUI->Enable(!m_Student.isNull()); } void CDocViewEx1Doc::OnDocumentModify() { CStudentDialog dlg; dlg.m_strName = m_Student.m_strName; dlg.m_nGrade = m_Student.m_nGrade; if (dlg.DoModal() == IDOK) { m_Student.m_strName = dlg.m_strName; m_Student.m_nGrade = dlg.m_nGrade; UpdateAllViews(NULL); } }
Update
void CDocViewEx1View::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { CDocViewEx1Doc *pDoc = GetDocument(); m_nGrade = pDoc->m_Student.m_nGrade; m_strName = pDoc->m_Student.m_strName; UpdateData(FALSE); }