类向导添加响应函数(三个)
编辑代码
void CView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
::SetCursor(LoadCursor(NULL, IDC_ARROW));
//注意以下几个变量要在头函数中定义
//bool m_Dragging; CPoint m_PointOrigin;CPoint m_PointOld;
m_Dragging = 1;
m_PointOrigin = point;
m_PointOld = point;
SetCapture();
RECT Rect;
GetClientRect(&Rect);
ClientToScreen(&Rect);
::ClipCursor(&Rect);
CScrollView::OnLButtonDown(nFlags, point);
}
void CView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_Dragging)
{
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.MoveTo(m_PointOrigin);
dc.LineTo(m_PointOld);
dc.MoveTo(m_PointOrigin);
dc.LineTo(point);
m_PointOld = point;
}
CScrollView::OnMouseMove(nFlags, point);
}
void CView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CClientDC dc(this);
if (m_Dragging)
{
m_Dragging = 0;
::ReleaseCapture();
::ClipCursor(NULL);
dc.SetROP2(R2_NOT);
dc.MoveTo(m_PointOrigin);
dc.LineTo(m_PointOld);
dc.MoveTo(m_PointOrigin);
dc.LineTo(point);
m_PointOld = point;
}
CScrollView::OnLButtonUp(nFlags, point);
}
结果截图
{
::SetCursor(m_HCross);
m_Dragging=1;
m_PointOrigin=point;
m_PointOld=point;
SetCapture();
RECT Rect;
GetClientRect(&Rect);
ClientToScreen(&Rect);
::ClipCursor (&Rect);
CView::OnLButtonDown(nFlags, point);
}
OnMouseMove(UINT nFlags, CPoint point)
{
if(m_Dragging)
{
CClientDC dc(this);
dc.SetROP2 (R2_NOT);
dc.MoveTo (m_PointOrigin);
dc.LineTo (m_PointOld);
dc.MoveTo (m_PointOrigin);
dc.LineTo (point);
m_PointOld=point;
}
CView::OnMouseMove(nFlags, point);
}
OnLButtonUp(UINT nFlags, CPoint point)
{ CClientDC dc(this);
if(m_Dragging)
{
m_Dragging=0;
::ReleaseCapture ();
::ClipCursor (NULL);
dc.SetROP2 (R2_NOT);
dc.MoveTo (m_PointOrigin);
dc.LineTo (m_PointOld);
dc.MoveTo (m_PointOrigin);
dc.LineTo (point);
m_PointOld=point;
}
CView::OnLButtonUp(nFlags, point);
}
用鼠标控制也可以实现,也就是在mousemove中加点代码,让线随着鼠标做运动。动脑子好好想想吧,代码就不贴了。好久没用过VC了,呵呵