U E D R , A S I H C RSS

5인용C++스터디/API에서MFC로

MFC란???

  • Microsoft Foundation Class library
  • 윈도우즈 프로그래밍을 보다 객체지향적으로 하기 위하여 MS에서 만든 클래스 라이브러리.

윈도우즈 프로그래밍에 필요한 요소들을 클래스로 포장

  • 에플리케이션 - CWinApp
  • 윈도우 - CWnd
  • 다이얼로그박스 - CDialog
  • DC - CDC
  • 펜 - CPen
  • 브퍼쉬 - CBrush
  • 비트맵 - CBitmap
  • 메뉴 - CMenu
  • 버튼 - CButton
  • 에디트박스 - CEdit

매크로와 가상함수를 이용한 메시지 처리

~cpp 
BEGIN_MESSAGE_MAP(CApplicationView, CView)
	//{{AFX_MSG_MAP(CApplicationView)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_KEYDOWN()
	ON_WM_KEYUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
~cpp 
class CApplicationView : public CView
{
	.
	.
	.

// Generated message map functions
protected:
	//{{AFX_MSG(CApplicationView)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG
	...
};
~cpp 
/////////////////////////////////////////////////////////////////////////////
// CApplicationView message handlers

void CApplicationView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnLButtonDown(nFlags, point);
}

void CApplicationView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnLButtonUp(nFlags, point);
}

void CApplicationView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CApplicationView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnKeyUp(nChar, nRepCnt, nFlags);
}

각종 툴과의 통합

  • AppWizard - 에플리케이션의 기본 구조를 자동으로 생성해주는 툴.
  • ClassWizard - 클래스의 함수 오버라이딩, 메시지 처리 등 복잡한 과정을 자동으로 처리해주는 툴.
  • WizardBar - ClassWizard의 축소판으로 사용하기 더욱 쉽고 편함.

Document/View 아키텍쳐

MFC로 만든 SDI 에플리케이션의 구조

MFC로 만든 MDI 에플리케이션의 구조

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:17
Processing time 0.0242 sec