Macros written statement .h, interface macros written in .cpp
.h file
#include <afxwin.h>
// MFC header files
// the CWinApp application class, the derived class (subclass)
class the MyApp: public the CWinApp
{
public:
// base class virtual function, derived classes override just
// MFC program entry address
Virtual BOOL the InitInstance ();
};
/ / frame type CFrameWnd derived class (subclass)
class of MyFrame: public CFrameWnd
{
public:
of MyFrame (); // constructor
// declaration macros, announcement message mapping must be in the class declaration,
DECLARE_MESSAGE_MAP ()
afx_msg the OnLButtonDown void (UINT, a CPoint);
afx_msg void OnChar (UINT, UINT, UINT);
afx_msg the OnPaint void ();
};
.cpp file:
#include"mfc.h"
MyApp app;
The InitInstance the MyApp :: BOOL ()
{
of MyFrame * = new new Frame of MyFrame;
Frame-> the ShowWindow (SW_SHOWNORMAL);
Frame-> the UpdateWindow ();
m_pMainWnd = Frame;
return TRUE;
}
// boundary macro, which has two parameters, The class, base class (class and the base classes)
BEGIN_MESSAGE_MAP (of MyFrame, the CFrameWnd)
ON_WM_LBUTTONDOWN () // to be declared in the header file
ON_WM_CHAR () // keyboard message
ON_WM_PAINT()
END_MESSAGE_MAP()
:: of MyFrame of MyFrame ()
{
the Create (NULL, the TEXT ( "MFC"));
}
// import header file #include <mfc.h> open, to put it differently #include "mfc.h" will open
The OnLButtonDown of MyFrame :: void (UINT, a CPoint Point)
{
/ *
TCHAR buf [1024];
wsprintf (buf, the TEXT ( "% D = X, Y = D%"), point.x, point.y);
the MessageBox ( buf);
* /
// mfc strings Cstring
CString STR;
str.format (the TEXT ( "D ,,,,,,,,, X = Y =% D%"), point.x, point.y);
the MessageBox (STR );
}
:: OnChar of MyFrame void (UINT Key, UINT, UINT)
{
CString STR;
str.format (the TEXT ( "% c pressed key"), Key);
the MessageBox (STR);
}
void MyFrame :: OnPaint()
{
CPaintDC dc (this); // this drawing device specified
dc.TextOutW (100,100, TEXT ( "tribal order")); // CDC drawing graphic can look inside
dc.Ellipse (10,10,100,100);
}