在CView中申请两个变量
private:
BOOL b_Bool;
CPtion p_ptPoint;
按WIn+W在视图类中添加WM_LBUTTONDOWN 、WM_LBUTTONUP、WM_MOSEMOVE消息;
//
//在视图类的析构函数中初始化鼠标按下与按下的鼠标坐标位置;
CTest_7View::CTest_7View()
{
// TODO: add construction code here
m_ctrlPoint= 0;
pt_OrdPotion=FALSE;
}
//
//获取鼠标当前的坐标,并将鼠标按下的消息设置为TRUE;
void CTest_7View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pt_OrdPotion = TRUE;
m_ctrlPoint= point;
CView::OnLButtonDown(nFlags, point);
}
//当鼠弹起
void CTest_7View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pt_OrdPotion = FALSE;
CView::OnLButtonUp(nFlags, point);
}
//
//开始绘制;
void CTest_7View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(PS_SOLID, 1, RGB(255, 0, 0)); //设置笔的类型
CPen *pOldPen = dc.SelectObject(&pen); //将设置的笔的类型设置给dc;
if(pt_OrdPotion == TRUE)//判断鼠标是否按下;
{
dc.MoveTo(m_ctrlPoint);
dc.LineTo(point);
m_ctrlPoint=point;
}
dc.SelectObject(pOldPen);
CView::OnMouseMove(nFlags, point);
}
//
VC++线条的绘制
最新推荐文章于 2024-02-03 00:06:15 发布