1.自定义消息(.h和.cpp均可) #define WM_EXESQL WM_USER+1 //WPARAM表示sql语句 2.消息映射(cpp) BEGIN_MESSAGE_MAP(CCHServerDlg, CDialogEx) ON_MESSAGE(WM_EXESQL, CCHServerDlg::OnExeSql) END_MESSAGE_MAP() 3.消息响应函数 3.1函数声明格式(.h头文件) afx_msg nExeSql(WPARAM wParam, LPARAM lParam); 3.2函数实现 (.cpp) LRESULT CCHServerDlg::OnExeSql(WPARAM wParam, LPARAM lParam) { //do sth. return 1; }