跟着老师敲完LBUTTONDOWN,MOUSEMOVE,LBUTTONUP后,本来是想鼠标左键按着不动来画图,但是程序运行时,没点鼠标左键,直接在客户区移动鼠标就开始画线了。
老师用的是vc++6.0,我用的vs2017
void CDrawingboardView::OnPenChoice(UINT id)
{
// TODO: 在此处添加实现代码.
switch (id)
{
case ID_RED:color = RGB(255, 0, 0); break;
case ID_GREEN:color = RGB(0, 255, 0); break;
case ID_BLUE:color = RGB(0, 0, 255); break;
case ID_YELLOW:color = RGB(255, 255, 0); break;
case ID_BLACK:color = RGB(0, 0, 0); break;
}
pen.DeleteObject();
pen.CreatePen(0, 1, color);
}
void CDrawingboardView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
spt.x = point.x;
spt.y = point.y;
CView::OnLButtonDown(nFlags, point);
}
void CDrawingboardView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CClientDC dc(this);//定义客户区显示器对象
dc.SelectObject(&pen);
ept.x = point.x;
ept.y = point.y;
if (spt.x >= 0)
{
dc.MoveTo(spt);
dc.LineTo(ept);
spt.x = ept.x;
spt.y = ept.y;
}
CView::OnMouseMove(nFlags, point);
}
void CDrawingboardView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
spt.x = -1;
CView::OnLButtonUp(nFlags, point);
}