MFC is Microsoft Foundation Class.
composed with combination of Win32 api and class (object-oriented)
MFC is almost depricated by many alternatives like .net WPF and other crossplatform GUI libraries
declare field HWnd inside header file to create child windows
- you need to call
Create()
method of them to replaceCreateWindow()
of win32
- you need to call
since MFC works as OOP wrapper of win32, message dealing system how win32 do with CALLBACK function is replaced by MessageMap macro inside HWnd
SDI
- CWinApp
- CFrameWind
- CView
- CDocument
MDI
Dialog based
MessageMap
- do work of CALLBACK funtion on MFC
- composed with two macros (at top of source);
BEGIN_MESSAGE_MAP( CustumView, CView )
END_MESSAGE_MAP()
- examples
OnCreate()
: mapped withWM_CREATE
(ON_WM_CREATE())OnSize()
: mapped withWM_SIZE
(ON_WM_SIZE())OnPaint()
: mapped withWM_PAINT
(ON_WM_PAINT())OnClose()
: mapped withWM_CLOSE
(ON_WM_CLOSE())ON_COMMAND( CHILD_ID, OnCustumFunction )
- this is macro inside message map
- unlike default mapping like
ON_WM_CREATE()
, this macro has two parametersCHILD_ID
: UINT value (normally defined by macro)OnCustumFunction
: void (*) (void) type function
- calls
OnCustumFunction()
when control withCHILD_ID
occur WM_COMMAND message
- message processing class
almost messages occur in CView type object. so message will be sent in CView’s MessageMap.
but if there’s no proper MessageMap in CView type object, it will be sent to CDocument type object’s MessageMap.
if there’s no MessageMap, next is CFrameWnd.
and next is CwinApp.
CView -> CDocument -> CFrameWnd -> CWinApp
CWinApp
InitInstance()
: called when mfc program startedRun()
: loop functionExitInstance()
: called when mfc progran ended
AfxMessageBox()
void AfxMessageBox( _T("text") );
- work as MessageBox of win32