▲ 连续划线
// 鼠标是否按下标志 点位变量
private:
// 是否按下
bool m_isPress;
// 存点数据
CPoint m_myPoint;
消息:
BEGIN_MESSAGE_MAP(CMFCApplication1View, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
ON_WM_LBUTTONDOWN() // 左键按下
ON_WM_LBUTTONUP() // 左键抬起
ON_WM_MOUSEMOVE() // 鼠标移动
END_MESSAGE_MAP()
消息实现:
void CMFCApplication1View::OnLButtonDown(UINT nFlags, CPoint point)
{
m_myPoint = point;
m_isPress = true;
CView::OnLButtonDown(nFlags, point);
}
void CMFCApplication1View::OnLButtonUp(UINT nFlags, CPoint point)
{
#ifdef MASK_THIS_BLOCK
CClientDC dc(this);
dc.MoveTo(m_myPoint);
dc.LineTo(point);
#endif // 0
m_isPress = false;
CView::OnLButtonUp(nFlags, point);
}
void CMFCApplication1View::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_isPress) {
CClientDC dc(this);
dc.MoveTo(m_myPoint);
dc.LineTo(point);
// 更新起点
m_myPoint = point;
}
CView::OnMouseMove(nFlags, point);
}
标签:MFC,point,画线,dc,nFlags,myPoint,CMFCApplication1View,CView
From: https://www.cnblogs.com/huvjie/p/17985514