STEP1:定义消息
#define UM_TEST WM_USER+1
STEP2:填写消息的映射关系
class CMainFrame : public CFrameWnd
{
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnTest();
//}}AFX_MSG
afx_msg LRESULT userMsgTest(WPARAM wParam,LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(IDM_TEST, OnTest)
//}}AFX_MSG_MAP
ON_MESSAGE(UM_TEST,userMsgTest)
END_MESSAGE_MAP()
STEP3:实现消息的响应函数
LRESULT CMainFrame::userMsgTest(WPARAM wParam,LPARAM lParam)
{
CString str;
str.Format("UM :%04x %08x ",wParam,lParam);
MessageBox(str);
return 0;
}
STEP4:发送消息
void CMainFrame::OnTest()
{
// TODO: Add your command handler code here
//SendMessage(UM_BTNCLK,0x4321,0x12345678);
PostMessage(UM_BTNCLK,0x4321,0x12345678);
}