可以把buttonID放到static UINT group[]={ID_BUTTON1....};

解决方案 »

  1.   

    1) .h文件中,添加
        afx_msg void OnButton( UINT id );2) 消息映射中,添加
    ON_COMMAND_RANGE(IDC_BUTTON1,IDC_BUTTON3,OnButton)
    IDC_BUTTON1最小值
    IDC_BUTTON3最大值3) 函数的实现:void CMyDlg::OnButton( UINT id ) 
    {
        CString str;
        str.Format("id=%d", id);
        MessageBox(str);
    }
      

  2.   

    同意 dyw(旺仔) , 标准方法.
      

  3.   

    从CButton类中派生出CMyButton类,在CMyButton中重载==运算符。
    然后,定义一个CMyButton数组m_Button[yourbuttoncount].void CTRCPDemoDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    //
        RECT Rect;
        for (int i=1; i<12; i++)
        {
            m_Button[i].GetWindowRect((LPRECT) &Rect);////////<<--------
            if (Rect.top < point.y && Rect.left < point.x && 
                Rect.right > point.x &&Rect.bottom > point.y) 
            {
       TRACE("PanLeft On \n");
                m_TRCPObject->buttonPress(i, 0);//根据ID 不同 (i)
            }   CDialog::OnLButtonDown(nFlags, point);
    }
    这样应该可以解决问题。
    如果不是非要在OnLButtonDown中解决问题,更好的解决方法是使用MFC 
    ON_CONTROL_RANGE宏。它将两个以上控件发出的同样的通知映射给共用的通知
    处理程序。类似的宏还有ON_COMMAND_RANGE宏,它将一组连续的命令ID映射为
    一个公用处理程序。