BEGIN_MSG_MAP(CMainFrame)
MESSAGE_HANDLER(WM_Create, OnCreate)
CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
END_MSG_MAP()
BEGIN_MSG_MAP(CGameView)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_Create, OnCreate)
COMMAND_ID_HANDLER(ID_GAME_START_NEW, OnGameStartNew)
END_MSG_MAP()
// register object for message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
class CGameView
: public CScrollWindowImpl<CGameView>
, public CMessageFilter
{
// ...
};
BEGIN_MSG_MAP(CMainFrame)
MESSAGE_HANDLER(WM_Create, OnCreate)
CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
CHAIN_MSG_MAP_MEMBER(m_view)
END_MSG_MAP()
BEGIN_MSG_MAP(CGameView)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_Create, OnCreate)
ALT_MSG_MAP(1) // Handle notify message.
COMMAND_ID_HANDLER(ID_GAME_START_NEW, OnGameStartNew)
END_MSG_MAP()
BEGIN_MSG_MAP(CMainFrame)
MESSAGE_HANDLER(WM_Create, OnCreate)
CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
CHAIN_MSG_MAP_ALT_MEMBER(m_view, 1)
END_MSG_MAP()
通过这种机制,我们可以很方便的在CMainFrame中将消息派发到不同的控件当中去,这样就比MFC的消息机制要灵活很多。
转自:http://blog.csdn.net/jjmm2035/article/details/3265952