::RegisterWindowMessage的用法

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)即可

posted @ 2010-08-13 20:30  小 楼 一 夜 听 春 雨  阅读(5881)  评论(0编辑  收藏  举报