比如多个菜单项共用同一个消息处理函数的时候,在这个函数中间怎么判断消息是从那个菜单项发送过来的?也就是如果这个处理函数没有wParam和lParam时,怎么在函数体中得到这两个参数?
谢谢!

解决方案 »

  1.   

    1
    Writing the Message-Map Entry
    In the .CPP file, add your message-map entry, as shown in the following example:
    ...
    BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
        //{{AFX_MSG_MAP(CMyApp)
        ...
        //}}AFX_MSG_MAP
    ON_COMMAND_RANGE(ID_MYCMD_ONE, ID_MYCMD_TEN, OnDoSomething)
    END_MESSAGE_MAP( )2
    Declaring the Handler Function
    In the .H file, add your handler function declaration outside the //{{AFX_MSG comment brackets. The following code shows how this might look, as shown in the next-to-last line below:
    // Generated message-map functions
    protected:
        //{{AFX_MSG(CMyApp)   
            ...
        //}}AFX_MSG
        afx_msg void OnDoSomething( UINT nID );
        DECLARE_MESSAGE_MAP()void CMyApp::OnDoSomething( UINT nID )
    {
        int nButton = nID - IDC_BUTTON1;
        switch(nButton)
        {
            case....
         }
        // ...
    }
      

  2.   

    参考
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_handlers_for_message.2d.map_ranges.asp
      

  3.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_on_command_range.asp
      

  4.   

    Command Routing 命令传递原理
    深入浅出MFC第2版 第147页
      

  5.   

    Replace ON_COMMAND with ON_COMMAND_EX
      

  6.   

    哇,这个砧子引来这么多大佬的光顾。Mark Mark Mark.