Posted on 2012-09-29 16:23
盛胜 阅读(652)
评论(0) 编辑 收藏 引用 所属分类:
vc++深入详解
在视图类中添加私有bool类型的m_bDraw,m_bDraw在视图类构造函数中初始化为FALSE.在OnLButtonDown和OnLButtonUp消息函数中分别设置为TRUE和FALSE。
在视图类添加私有CPoint类型m_ptOld,在OnLButtonDown消息函数中初始化这个变量m_ptOld=point;
void CTestView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//扇形
CClientDC dc(this);
//SetROP2设置绘图模式函数
//dc.SetROP2(R2_BLACK);
//dc.SetROP2(R2_MERGENOTPEN);
CPen pen(PS_SOLID,1,#ff0000);
CPen *pOldpen=dc.SelectObject(&pen);
if(TRUE==m_bDraw)
{
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.LineTo(m_ptOld);
m_ptOld=point;
}
dc.SelectObject(pOldpen);
//连续线条
/*
CClientDC dc(this);
CPen pen(PS_SOLID,3,#ff0000);
CPen *pOldPen=dc.SelectObject(&pen);
if(TRUE==m_bDraw)
{
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
m_ptOrigin=point;
}
dc.SelectObject(pOldPen);
*/
CView::OnMouseMove(nFlags, point);
}