WEB开发网
开发学院软件开发VC VC中利用MFC设计绘图程序初步 阅读

VC中利用MFC设计绘图程序初步

 2007-03-15 21:46:03 来源:WEB开发网   
核心提示: 思路:鼠标移动的信号被捕捉到,然后随时响应该信号,VC中利用MFC设计绘图程序初步(2),绘制图线,这里要设置一个BOOL变量 m_bDraw 来判断是否鼠标左键按下了,//画连续的线条void CDrawView::OnMouseMove(UINT nFlags, CPoint poin

思路:鼠标移动的信号被捕捉到,然后随时响应该信号,绘制图线。

这里要设置一个BOOL变量 m_bDraw 来判断是否鼠标左键按下了。

//画连续的线条
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
 if ( m_bDraw )
 {
  CClientDC dc(this) ;
  dc.MoveTo(m_ptOrigin); //移动到原来的点
  dc.LineTo(point); //绘制直线
  m_ptOrigin = point ; //将现在的点赋值给原来的坐标,以便下次调用
 }
 CView::OnMouseMove(nFlags, point);
}
//改变画笔的颜色
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
 if ( m_bDraw )
 {
  CClientDC dc(this) ;
  CPen pen( PS_SOLID , 1 , RGB(255,128,128) );
  CPen *pOldPen = dc.SelectObject(&pen);
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
  m_ptOrigin = point ;
  dc.SelectObject(pOldPen);
 }
 CView::OnMouseMove(nFlags, point);
}
//画扇型
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
 if ( m_bDraw )
 {
  CClientDC dc(this) ;
  CPen pen( PS_SOLID , 1 , RGB(255,128,128) );
  CPen *pOldPen = dc.SelectObject(&pen);
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(m_ptOld);
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
  m_ptOld = point ;
  dc.SelectObject(pOldPen);
 }
 CView::OnMouseMove(nFlags, point);
}
//画带边线的扇型
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
 if ( m_bDraw )
 {
  CClientDC dc(this) ;
  CPen pen( PS_SOLID , 1 , RGB(255,128,128) );
  CPen *pOldPen = dc.SelectObject(&pen);
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(m_ptOld);
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
  dc.MoveTo(m_ptOld);
  dc.LineTo(point);
  m_ptOld = point ;
  dc.SelectObject(pOldPen);
 }
 CView::OnMouseMove(nFlags, point);
}
//看看绘图的模式设置方法
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
 if ( m_bDraw )
 {
  CClientDC dc(this) ;
  dc.SetROP2(R2_BLACK); //绘图的模式设置,始终绘制黑色图形
  CPen pen( PS_SOLID , 1 , RGB(255,128,128) );
  CPen *pOldPen = dc.SelectObject(&pen);
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(m_ptOld);
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
  dc.MoveTo(m_ptOld);
  dc.LineTo(point);
  m_ptOld = point ;
  dc.SelectObject(pOldPen);
 }
 CView::OnMouseMove(nFlags, point);
}

到此,我们知道了一般地绘图方法了。

上一页  1 2 

Tags:VC 利用 MFC

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接