首页 > 编程地带 > VC++-简单绘图

VC++-简单绘图

2008年7月19日 发表评论 阅读评论

本文只给出相关函数。请根据需要去掉对应的注释部分。
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
  // TODO: Add your message handler code here and/or call default
  //利用SDK函数画线
/*
  HDC hdc;
  hdc = ::GetDC(m_hWnd);
  MoveToEx(hdc,m_ptOrigin.x, m_ptOrigin.y, NULL);
  LineTo(hdc,point.x,point.y);
  ::ReleaseDC(m_hWnd,hdc);
  CView::OnLButtonUp(nFlags, point);
*/
  //利用MFC的CDC类实现画线
/*  
  CDC* pDC = GetDC();
  pDC->MoveTo(m_ptOrigin);
  pDC->LineTo(point);
  ReleaseDC(pDC);
*/
  //利用MFC的CClientDC类实现画线
/*
  CClientDC dc(GetParent());
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
*/
  //利用MFC的CWindowsDC类实现画线
/*
  CWindowDC dc(GetParent());
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
*/

  //在桌面窗口中画线
/*
  CWindowDC dc(GetDesktopWindow());
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
*/
  //绘制彩色线条
/*
  CPen pen(PS_DOT,1,RGB(0,0,255));
  CWindowDC dc(GetDesktopWindow());
  CPen* pOldPen = dc.SelectObject(&pen);
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
  dc.SelectObject(pOldPen);
*/
  //画刷
/*
  CBrush brush(RGB(0,0,255));
  CWindowDC dc(GetDesktopWindow());
  dc.FillRect(CRect(m_ptOrigin,point),&brush);
*/

  //位图画刷
/*
  CBitmap bitmap;
  bitmap.LoadBitmap(IDB_BITMAP1);
  CBrush brush(&bitmap);
  CWindowDC dc(GetDesktopWindow());
  dc.FillRect(CRect(m_ptOrigin,point),&brush);
*/
  //透明画刷
/*
  CWindowDC dc(GetDesktopWindow());
  CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
  CBrush *pOldBrush = dc.SelectObject(pBrush);
  dc.Rectangle(CRect(m_ptOrigin,point));
  dc.SelectObject(pOldBrush);
*/              
}

绘制连续的线条(三种方法):
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
  // TODO: Add your message handler code here and/or call default
/*
  CWindowDC dc(GetDesktopWindow());
  if ( m_bDraw == TRUE)
  {
    dc.MoveTo(m_ptOrigin);
    dc.LineTo(point);
    m_ptOrigin = point;
  }
*/

/*
  HDC hdc;
  hdc = ::GetDC(m_hWnd);
  if ( m_bDraw == TRUE)
  {
  MoveToEx(hdc,m_ptOrigin.x, m_ptOrigin.y, NULL);
  LineTo(hdc,point.x,point.y);
  m_ptOrigin = point;
  ::ReleaseDC(m_hWnd,hdc);
  }
*/
  CClientDC dc(this);
  if ( m_bDraw == TRUE)
  {
    dc.MoveTo(m_ptOrigin);
    dc.LineTo(point);
    m_ptOrigin = point;
  }
  CView::OnMouseMove(nFlags, point);
}

转载请注明:woyigui's blog [http://www.woyigui.cn/]
本文标题:VC++-简单绘图
本文地址:http://www.woyigui.cn/2008/07/19/vc-Simple-graphics/

分类: 编程地带 标签: ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
*