不太想用CCommandButton
因为会在显示上和我的程序出一些冲突!而且也不需要把么多功能!只要有鼠标按下和抬起的响应事件就行了!谢谢帮忙啊!

解决方案 »

  1.   

    自己从CButton派生一个子类,在其中映射消息.
      

  2.   

    // h文件
    class CMsgButton : public CButton
    {
    DECLARE_DYNAMIC(CMsgButton)public:
    CMsgButton();
    virtual ~CMsgButton();protected:
    DECLARE_MESSAGE_MAP()
    public:
    afx_msg void OnBnClicked();
    };// cpp文件
    // CMsgButtonIMPLEMENT_DYNAMIC(CMsgButton, CButton)CMsgButton::CMsgButton()
    {}CMsgButton::~CMsgButton()
    {
    }
    BEGIN_MESSAGE_MAP(CMsgButton, CButton)
    ON_CONTROL_REFLECT(BN_CLICKED, &CMsgButton::OnBnClicked)
    END_MESSAGE_MAP()// CMsgButton 消息处理程序void CMsgButton::OnBnClicked()
    {
    // TODO: 在此添加控件通知处理程序代码
    }-----------------------------------------------
    MyCSDN 免费版 - http://community.csdn.net/Expert/TopicView1.asp?id=4608614
      

  3.   

    从CButton派生CMyButton类,然后在ClassWizard中选择消息“WM_LBUTTONDOWN”和“WM_LBUTTONUP”,自己重写一下这两个函数不就可以了吗。。
      

  4.   

    派生一个子类,继承 CButton ,然后用VC的ClassWizard把你需要的消息实现出来就行了,非常简单
      

  5.   

    1、子类化按钮,当按钮按下和弹出时响应
    2、在对话框中重载PreTranslateMessage,处理如下:
    BOOL 类名::PreTranslateMessage(MSG* pMsg) 
    {
    switch (pMsg->message)
    {
    case WM_LBUTTONDOWN:

    if(pMsg->hwnd == GetDlgItem(IDC_BTN_UP)->m_hWnd)
    {
    // 是(IDC_BTN_UP)按下
    }

    case WM_LBUTTONUP:
    if(pMsg->hwnd == GetDlgItem(IDC_BTN_UP)->m_hWnd)
    {
    // 是(IDC_BTN_UP)松开
    }
    }
    return CDialog::PreTranslateMessage(pMsg);
    }