//In class declaration (.H file ).private :CButton* m _pButton ;//In class implementation (.cpp file ) .m_pButton =new CButton ;ASSERT_VALID (m_pButton);m_pButton —>Create (_T ("Button Title ") , WS_CHILD |WS_VISIBLE |BS_PUSHBUTTON.Crect ( 0, 0, 100 , 24) , this , IDC _MYBUTTON )

解决方案 »

  1.   

    BOOL C..Dlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    //m_pButton 为按钮CButton实例变量。
    if(pMsg->hwnd==m_pButton.m_hWnd){
    if(pMsg->message==WM_LBUTTONUP){
    CRect rect;
    m_pButton.GetWindowRect(&rect);
    if(rect.PtInRect(pMsg->pt)){                          // add you code here
                             return true;
    }
    }
    if(pMsg->message==WM_KEYDOWN){
    // add you code here
                      return true;
    }
    }
    //
    //
    return CDialog::PreTranslateMessage(pMsg);
    }
      

  2.   

    还不清楚吗????不就是利用 pMsg->hwnd 判断那个按钮被激活吗?然后就可以执行相应的代码了。