vc画出鼠标一定轨迹

首先添加鼠标的LBUTTONDOWN事件处理函数,记录鼠标按下的位置

void CTestDemoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
  // TODO: Add your message handler code here and/or call default
   m_iPrevX=point.x;
   m_iPrevY=point.y;
  return; 
  //CDialog::OnLButtonDown(nFlags, point);
}

接着添加鼠标的MOUSEMOVE事件处理函数,记录当前鼠标位置,并画线连接上一位置与当前位置

void CMouseDlg::OnMouseMove(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    if((nFlags & MK_LBUTTON)==MK_LBUTTON)
   {
       CClientDC dc(this);
     dc.MoveTo(m_iPrevX,m_iPrevY);
     dc.LineTo(point.x,point.y);
     m_iPrevX=point.x;
     m_iPrevY=point.y;
    //dc.SetPixel(point.x,point.y,RGB(0,0,0));
   }
   CDialog::OnMouseMove(nFlags, point);
}

posted @ 2009-03-04 14:12  笑三少  阅读(478)  评论(0)    收藏  举报