windows消息机制一
dlg.cpp添加
#define MY_MESSAGE WM_USER + 1000
dlg.h添加
afx_msg LRESULT onMyMessage(WPARAM wparam, LPARAM lparam);
dlg.cpp添加
ON_MESSAGE(MY_MESSAGE , onMyMessage)
LRESULT CMfcTestDlg::onMyMessage(WPARAM wparam, LPARAM lparam)
{
if (wparam == 1 && lparam == 0)
MessageBox(TEXT("receieve my message"));
return 0;
}
方法2
dlg.cpp添加
#define GAME_MSG TEXT("game message")
UINT gameMessage = 0;
在初始化对话框中加入
gameMessage = ::RegisterWindowMessage(GAME_MSG);
并将ON_MESSAE(...)改成
ON_REGISTERED_MESSAGE(gameMessage, onMyMessage)即可