MFC中消息映射机制(BEGIN_MESSAGE_MAP和END_MESSAGE_MAP)

 

DECLARE_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CtestDialogDlg, CDialogEx)
    ON_WM_PAINT()            //OnPaint()
    ON_WM_QUERYDRAGICON()    //
    ON_WM_SYSCOMMAND()        //OnSysCommand()
    ON_WM_SIZE()            //OnSize()
    ON_MESSAGE(WM_USER_MSG, &CtestDialogDlg::OnUserMsg) //自定义消息
...









END_MESSAGE_MAP()

自定义消息的步骤:
1. 头文件中
#define WM_USER_MSG   (WM_USER + 1) 
afx_msg LRESULT OnUserMsg(WPARAM wParam, LPARAM lParam);
2. cpp文件中
BEGIN_MESSAGE_MAP(CtestDialogDlg, CDialogEx)
    ON_MESSAGE(WM_USER_MSG, &CtestDialogDlg::OnUserMsg) //自定义消息
END_MESSAGE_MAP()
afx_msg LRESULT CtestDialogDlg::OnUserMsg(WPARAM wParam, LPARAM lParam)
{
    ....
    return 0;
}

posted @ 2019-11-14 22:01  htj10  阅读(1119)  评论(0编辑  收藏  举报
TOP