![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
2
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
3
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
这些都是宏定义,不是函数。
在BEGIN_MESSAGE_MAP()和END_MESSAGE_MAP()之间添加你的消息响应函数,为每个消息处理函数加入一个入口
BEGIN_MESSAGE_MAP( theClass, baseClass )
参数:
theClass | 指定消息映射所属的类的名字。 |
baseClass | 指定theClass的基类的名字。 |
说明:
使用BEGIN_MESSAGE_MAP宏开始你的消息映射的定义。
在你的类的成员函数的实现文件(.CPP)中,使用BEGIN_MESSAGE_MAP宏开始消息映射,然后为每个消息处理函数加入一个入口,最后用END_MESSAGE_MAP宏结束消息映射。
每个消息映射入口的格式如下:
ON_COMMAND(id, memberFxn)
其中id指定了发送通知的控件的子窗口的ID(即该ID的事件被触发了就会调用 memberFxn指向的函数) ,而memberFxn指定了处理该通知的成员函数名 。
也可能无参数如: ON_WM_SYSCOMMAND()
函数原型格式如下:
afx_msg void memberFxn( );
可能的消息映射入口如下:
映射入口 | 何时向父对象发送消息 |
ON_BN_CLICKED | 用户单击按钮时 |
ON_BN_DOUBLECLICKED | 用户双击按钮时 |
例如:
BEGIN_MESSAGE_MAP(CUEConnServerApp, CWinApp)
//{{AFX_MSG_MAP(CUEConnServerApp)
ON_COMMAND(ID_APP_SHOW, OnAppShow)
ON_COMMAND(ID_APP_EXIT, OnAppExit)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_HELP_INDEX, OnHelpIndex)
//}}AFX_MSG_MAP
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
又如:
BEGIN_MESSAGE_MAP(CAirFlux_Proxy_TeyDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
例如:
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
2
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
3
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
4
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
5
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
6
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
7
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
8
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
void CTestDlg::OnSysCommand (UINT nID, LPARAM lParam)
这个函数响应系统控制菜单的命令 .(即左上角图标处)。
OnSysCommand:The framework calls this member function when the user selects a command from the Control menu, or when the user selects the Maximize or the Minimize button.
另外:
DoDataExchange:当UpdateData时候
OnInitDialog:对话框类已经构造,但是对话框还没有显示出来的时候
OnQueryDragIcon :The framework calls this member function by a minimized (iconic) window that does not have an icon defined for its class. The system makes this call to obtain the cursor to display while the userdrags the minimized window .