1. 程式人生 > >用mfc畫動態直線--“橡皮線"

用mfc畫動態直線--“橡皮線"

用mfc畫動態直線--“橡皮線”

筆記:程式碼在CView.cpp裡實現

//CView

CPoint m_ptSpoint;  //起始點
CPoint m_ptEpoint;  //最終點
bool m_click;

//上面三個變數也可定義在Cview.h裡

void CDrawLineView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此新增訊息處理程式程式碼和/或呼叫預設值

	m_ptSpoint =m_ptEpoint= point;
	m_click = true;

	CView::OnLButtonDown(nFlags,
point); } void CDrawLineView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: 在此新增訊息處理程式程式碼和/或呼叫預設值 m_click = false; CView::OnLButtonUp(nFlags, point); } void CDrawLineView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: 在此新增訊息處理程式程式碼和/或呼叫預設值 CDC*p = GetDC(); if (m_click == true) { p-
>SetROP2(R2_NOT); p->MoveTo(m_ptSpoint); p->LineTo(m_ptEpoint); m_ptEpoint = point; p->MoveTo(m_ptSpoint); p->LineTo(m_ptEpoint); } CView::OnMouseMove(nFlags, point); }