我想在toolbar的按钮响应鼠标左键的down和up事件,怎样实现?

解决方案 »

  1.   

    在工具栏按钮的消息响应函数中发送down和up消息
      

  2.   

    BEGIN_MSG_MAP 
    MESSAGE_HANDLER(WM_COMMAND, OnCommand)
    END_MSG_MAP()
    处理Command消息
      

  3.   

    上面的代码是down,不是up,也就是怎样响应释放左键的事键呀
      

  4.   

    简单的方法:
    在MainFrm.h中加
    //{{AFX_MSG(CMainFrame)
    afx_msg void Onyourfun();
    //}}AFX_MSG在MainFrm.cpp中加
    //{{AFX_MSG_MAP(CMainFrame)
    ON_COMMAND(ID_your_toolbar, Onyourfun)
    //}}AFX_MSG_MAP
    ...void CMainFrame::Onyourfun() 
    {
    // TODO: Add your command handler code here
    }
    函数Onyourfun能响应你的点击事件,可以当作up事件
    -------------------------------------------------------------------复杂的方法:
    继承CToolBar,然后在CyourToolBar中,接收鼠标左键消息。
      

  5.   

    MESSAGE_HANDLER( WM_LBUTTONUP, OnLeftButtonUp )
      

  6.   

    楼上的大哥
    void CMainFrame::Onyourfun() 

    // TODO: Add your command handler code here 

    函数Onyourfun能响应你的点击事件,可以当作up事件 
    我要区分up和down的事件,你这个函数没有什么作用呀
      

  7.   

    重载框架类的PreTranslateMessage函数:
    BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
    {
    if (pMsg->message == WM_LBUTTONUP && pMsg->hwnd == m_wndToolBar.m_hWnd)
    {
    // ……
    }
    return CFrameWnd::PreTranslateMessage(pMsg);
    }
      

  8.   

    WM_LBUTTONDOWN, WM_LBUTTONUP 处理down 和up事件