技术开发 频道

VC6类向导对窗体按钮添加的消息映射代码


【IT168技术文档】

  1.在窗体头文件(如:MyDlg.h)中声明消息处理函数OnButton1:
protected: // Generated message map functions //{{AFX_MSG(CMyDlg) afx_msg void OnButton1(); //}}AFX_MSG
  2.在MyDlg.cpp源文件开头部分的消息映射入口,添加相应的消息映射宏:
  这段代码,表明消息及其处理函数之间的联系。当用户单击按钮控件IDC_BUTTON1 时,
  系统将自动调用OnButton1函数。
BEGIN_MESSAGE_MAP(CMyDlg, CDialog) //{{AFX_MSG_MAP(CMyDlg) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP END_MESSAGE_MAP()
  3.在MyDlg.cpp文件中写入一个空的消息处理函数的模板,以便用户填入具体代码,如下面的框架:
void CMyDlg::OnButton1() { // TODO: Add your control notification handler code here }
  在消息映射函数体框架中用户可以添加一些代码,例如:
void CMyDlg::OnButton1() { // TODO: Add your control notification handler code here MessageBox(“消息映射机制!”); }
0
相关文章