当左键按下按钮不松开鼠标时,消息如何响应?
当左键松开时,消息又如何响应?
谢谢啦

解决方案 »

  1.   

    wm_mousemove消息的参数可以标识按键是否按下
    有buttondown消息,但无buttonup消息 也可视作常按
      

  2.   

    当左键按下按钮不松开鼠标时,消息如何响应?
    当左键松开时,消息又如何响应?
    ===================================================
    这里有几个消息都会产生,按下时产生:WM_LBUTTONDOWN,不松开时有WM_MOUSEMOVE消息,松开时会产生:WM_LBUTTONUP消息。
      

  3.   

    重载按钮CButtong,在WM_LBUTTONDOWN消息中设置一个布尔变量为真,并且用SetCapture捕获鼠标消息,在WM_LBUTTONUP中设置该布尔变量为假。WM_MOUSEMOVE消息无论鼠标是否按下都会产生。也可以在鼠标按下后设置定时器,在定时器中进行处理,鼠标释放后销毁定时器。
      

  4.   

    Mackz(在相互)可不可以给几行代码参考一下?谢谢!
      

  5.   

    应用Mackz(在相互)的方法.mfc windows 编程一书中有一个相似的例子.截取其中程序片段,自己看看:void CMainWindow::OnLButtonDown (UINT nFlags, CPoint point)
    {
    //
    // Record the anchor point and set the tracking flag.
    //
        m_ptFrom = point;
        m_ptTo = point;
        m_bTracking = TRUE; //
    // If capture is enabled, capture the mouse.
    //
        if (m_bCaptureEnabled)
            SetCapture ();
    }void CMainWindow::OnMouseMove (UINT nFlags, CPoint point)
    {
    //
    // If the mouse is moved while we're "tracking" (that is, while a
    // line is being rubber-banded), erase the old rubber-band line and
    // draw a new one.
    //
        if (m_bTracking) {
            CClientDC dc (this);
            InvertLine (&dc, m_ptFrom, m_ptTo);
            InvertLine (&dc, m_ptFrom, point);
            m_ptTo = point;
        }
    }void CMainWindow::OnLButtonUp (UINT nFlags, CPoint point)
    {
    //
    // If the left mouse button is released while we're tracking, release
    // the mouse if it's currently captured, erase the last rubber-band
    // line, and draw a thick red line in its place.
    //
        if (m_bTracking) {
            m_bTracking = FALSE;
            if (GetCapture () == this)
                ::ReleaseCapture ();        CClientDC dc (this);
            InvertLine (&dc, m_ptFrom, m_ptTo);        CPen pen (PS_SOLID, 16, RGB (255, 0, 0));
            dc.SelectObject (&pen);        dc.MoveTo (m_ptFrom);
            dc.LineTo (point);
        }
    }void CMainWindow::OnNcLButtonDown (UINT nHitTest, CPoint point)
    {
    //
    // When the window's title bar is clicked with the left mouse button,
    // toggle the capture flag on or off and update the window title.
    //
        if (nHitTest == HTCAPTION) {
            m_bCaptureEnabled = m_bCaptureEnabled ? FALSE : TRUE;
            SetWindowText (m_bCaptureEnabled ?
                _T ("Mouse Capture Demo (Capture Enabled)") :
                _T ("Mouse Capture Demo (Capture Disabled)"));
        }
        CFrameWnd::OnNcLButtonDown (nHitTest, point);
    }