////////////////////////////////////////////////////////////////////// Recall the Macro definition of DECLARE_MESSAGE_MAP() #define DECLARE_MESSAGE_MAP() \ private: \ static const AFX_MSGMAP_ENTRY _messageEntries[]; \ protected: \ static AFX_DATA const AFX_MSGMAP messageMap; \ static const AFX_MSGMAP* PASCAL _GetBaseMessageMap(); \ virtual const AFX_MSGMAP* GetMessageMap() const; \ struct AFX_MSGMAP_ENTRY { UINT nMessage; // windows message UINT nCode; // control code or WM_NOTIFY code UINT nID; // control ID (or 0 for windows messages) UINT nLastID; // used for entries specifying a range of control id's UINT nSig; // signature type (action) or pointer to message # AFX_PMSG pfn; // routine to call (or special value) }; struct AFX_MSGMAP { const AFX_MSGMAP* (PASCAL* pfnGetBaseMap)(); const AFX_MSGMAP_ENTRY* lpEntries; }; typedef void (AFX_MSG_CALL CCmdTarget::*AFX_PMSG)(void); ////////////////////////////////////////////////////////////////////// #define BEGIN_MESSAGE_MAP(theClass, baseClass) \ const AFX_MSGMAP* PASCAL theClass::_GetBaseMessageMap() \ { return &baseClass::messageMap; } \ const AFX_MSGMAP* theClass::GetMessageMap() const \ { return &theClass::messageMap; } \ AFX_COMDAT AFX_DATADEF const AFX_MSGMAP theClass::messageMap = \ { &theClass::_GetBaseMessageMap, &theClass::_messageEntries[0] }; \ AFX_COMDAT const AFX_MSGMAP_ENTRY theClass::_messageEntries[] = \ { \ /////////////////////////////////////////////////////////////////////// Using this definition, then the following line: BEGIN_MESSAGE_MAP(CSketcherApp, CWinApp) will become, after preprocessor, the following: /////////////////////////////////////////////////////////////////////// const AFX_MSGMAP* PASCAL CSketcherApp::_GetBaseMessageMap() { return &CWinApp::messageMap; } const AFX_MSGMAP* CSketcherApp::GetMessageMap() const { return &CSketcherApp::messageMap; } AFX_COMDAT AFX_DATADEF const AFX_MSGMAP CSketcherApp::messageMap = { &CSketcherApp::_GetBaseMessageMap, &CSketcherApp::_messageEntries[0] }; AFX_COMDAT const AFX_MSGMAP_ENTRY CSketcherApp::_messageEntries[] = { ////////////////////////////////////////////////////////////////////// BEGIN_MESSAGE_MAP(CSketcherApp, CWinApp) //{{AFX_MSG_MAP(CSketcherApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) END_MESSAGE_MAP() where in the file afxmsg.h, we find #define ON_COMMAND(id, memberFxn) \ { WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)id, AfxSig_vv, (AFX_PMSG)&memberFxn }, and #define END_MESSAGE_MAP() \ {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } \ }; \ This block of codes now looks like the following: ////////////////////////////////////////////////////////////////////// const AFX_MSGMAP* PASCAL CSketcherApp::_GetBaseMessageMap() { return &CWinApp::messageMap; } const AFX_MSGMAP* CSketcherApp::GetMessageMap() const { return &CSketcherApp::messageMap; } AFX_COMDAT AFX_DATADEF const AFX_MSGMAP CSketcherApp::messageMap = { &CSketcherApp::_GetBaseMessageMap, &CSketcherApp::_messageEntries[0] }; AFX_COMDAT const AFX_MSGMAP_ENTRY CSketcherApp::_messageEntries[] = { //{{AFX_MSG_MAP(CSketcherApp) { WM_COMMAND, CN_COMMAND, (WORD)ID_APP_ABOUT, (WORD)ID_APP_ABOUT, AfxSig_vv, (AFX_PMSG)&OnAppAbout }, { WM_COMMAND, CN_COMMAND, (WORD)ID_FILE_NEW, (WORD)ID_FILE_NEW, AfxSig_vv, (AFX_PMSG)&CWinApp::OnFileNew }, { WM_COMMAND, CN_COMMAND, (WORD)ID_FILE_OPEN, (WORD)ID_FILE_OPEN, AfxSig_vv, (AFX_PMSG)&CWinApp::OnFileOpen }, { WM_COMMAND, CN_COMMAND, (WORD)ID_FILE_PRINT_SETUP, (WORD)ID_FILE_PRINT_SETUP, AfxSig_vv, (AFX_PMSG)&CWinApp::OnFilePrintSetup }, { 0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } };