就是一些宏:
#define BEGIN_MESSAGE_MAP(theClass, baseClass) /const AFX_MSGMAP* theClass::GetMessageMap() const /
{ return &theClass::messageMap; } /AFX_COMDAT AFX_DATADEF const AFX_MSGMAP theClass::messageMap = /
{ &baseClass::messageMap, &theClass::_messageEntries[0] }; /AFX_COMDAT const AFX_MSGMAP_ENTRY theClass::_messageEntries[] = /
{#define ON_MESSAGE(message, memberFxn) /
{ message, 0, 0, 0, AfxSig_lwl,(AFX_PMSG)(AFX_PMSGW)(LRESULT MSG_CALL 
CWnd::*)(WPARAM, LPARAM))&memberFxn },#define END_MESSAGE_MAP() /
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } 

}; 
可见:
BEGIN_MESSAGE_MAP(theClass, baseClass) 
  ON_MESSAGE(message, memberFxn) 
END_MESSAGE_MAP() 
就被扩展成:
const AFX_MSGMAP* theClass::GetMessageMap() const 
{ return &theClass::messageMap; } AFX_COMDAT AFX_DATADEF const AFX_MSGMAP theClass::messageMap = 
{ &baseClass::messageMap, &theClass::_messageEntries[0] }; AFX_COMDAT const AFX_MSGMAP_ENTRY theClass::_messageEntries[] = 
{
   { message, 0, 0, 0, AfxSig_lwl,(AFX_PMSG)(AFX_PMSGW)(LRESULT MSG_CALL Wnd::*)(WPARAM, LPARAM))&memberFxn },
   {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } 
}; 很明显,就是实现了函数:GetMessageMap() 
并且初始化了两个成员变量messageMap, _messageEntries[]变量的值 。

解决方案 »

  1.   

    补充一下:
    struct AFX_MSGMAP
    {
    #ifdef _AFXDLL
    const AFX_MSGMAP* (PASCAL* pfnGetBaseMap)();
    #else
    const AFX_MSGMAP* pBaseMap;
    #endif
    const AFX_MSGMAP_ENTRY* lpEntries;
    };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)
    };MFC类在处理消息时(就是在窗口函数里)估计是这样做的:LRESULT CALLBACK WindowProc(  HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam  )
    {
      AFX_MSGMAP * pMsgMap = GetMessageMap();
      AFX_MSGMAP_ENTRY* lpEntries = pMsgMap->lpEntries;  for(int i=0; lpEntries[i].nSig != AfxSig_end; i++) {
        if(uMsg == lpEntries[i].nMessage) {
           //这里还要判断是哪种消息以便把wParam,lParam转换为适当的形式
           (*lpEntries[i].fpn)(uMsg, wParam, lParam);
           return TRUE;
        }  
      }
      return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    嘿嘿,太多了