头文件
在这里插#include<afxwin.h>
class MyApp :public CWinApp
{
public:
BOOL InitInstance();//程序入口函数
};
class MyFram :public CFrameWnd
{
public:
MyFram();
DECLARE_MESSAGE_MAP();//消息映射宏,添加消息处理函数之前必须添加消息映射宏
afx_msg void OnLButtonDown(UINT, CPoint);
afx_msg void OnChar(UINT, UINT, UINT);
afx_msg void OnPaint();
};入代码片
源文件
在这里插
#include "mfc.h"
MyApp app;
BOOL MyApp::InitInstance()
{
MyFram *fram = new MyFram;
fram->ShowWindow(SW_SHOWNORMAL);
fram->UpdateWindow();
m_pMainWnd = fram;
return TRUE;
}
BEGIN_MESSAGE_MAP(MyFram,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_CHAR()
ON_WM_PAINT()
END_MESSAGE_MAP()
//BEGIN_MESSAGE_MAP(MyFram,CFrameWnd) END_MESSAGE_MAP()
//分界宏,分界宏中间放映射入口
MyFram::MyFram()
{
Create(NULL, TEXT("MFC"));
}
void MyFram::OnLButtonDown(UINT, CPoint point)
{
// TCHAR buf[1024];
// wsprintf(buf, TEXT("x=%d y=%d"), point.x, point.y);
// MessageBox(buf, TEXT("hello"), 0);
CString str;
str.Format(TEXT("x=%d , y=%d"), point.x, point.y);
MessageBox(str);
}
void MyFram::OnChar(UINT key, UINT num, UINT)
{
CString str;
str.Format(TEXT("按下%c键 %d次"), key, num);
MessageBox(str);
}
void MyFram::OnPaint()
{
CPaintDC dc(this);
dc.TextOutW(300,20,TEXT("王者荣耀"));
dc.Ellipse(500, 100, 10, 300);
}入代码片