MFC之设备描述表DC、画笔Pen、画刷Brush
2016-10-28 11:11
603 查看
1.利用SDK全局函数实现画线功能
2.利用MFC的CDC类实现画线功能
3.利用MFC的CClientDC类实现画线功能
4.利用MFC的CWindewDC类实现画线功能
5.绘制彩色线条
6.使用画刷绘图
7.位图画刷
8.透明画刷
9.绘制连续线条
10.绘制扇形效果的线条
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { 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); }
2.利用MFC的CDC类实现画线功能
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CDC *pDC=GetDC(); pDC->MoveTo(m_ptOrigin); pDC->LineTo(point); ReleaseDC(pDC); CView::OnLButtonUp(nFlags, point); }
3.利用MFC的CClientDC类实现画线功能
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CClientDC dc(this); CPen *pOldPen=dc.SelectObject(&pen); dc.MoveTo(m_ptOrigin); dc.LineTo(point); CView::OnLButtonUp(nFlags, point); }
4.利用MFC的CWindewDC类实现画线功能
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CWindowDC dc(this); //CWindowDC dc(GetParent()); //CWindowDC dc(GetDesktopWindow()); dc.MoveTo(m_ptOrigin); dc.LineTo(point); CView::OnLButtonUp(nFlags, point); }
5.绘制彩色线条
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CPen *pOldPen=dc.SelectObject(&pen); dc.MoveTo(m_ptOrigin); dc.LineTo(point); dc.SelectObject(pOldPen); CView::OnLButtonUp(nFlags, point); }
6.使用画刷绘图
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CBrush brush(RGB(255,0,0)); CClientDC dc(this); dc.FillRect(CRect(m_ptOrigin,point),&brush); CView::OnLButtonUp(nFlags, point); }
7.位图画刷
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP1); CBrush brush(&bitmap); CClientDC dc(this); dc.FillRect(CRect(m_ptOrigin,point),&brush); CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); CBrush *pOldBrush=dc.SelectObject(pBrush); dc.Rectangle(CRect(m_ptOrigin,point)); dc.SelectObject(pOldBrush); CView::OnLButtonUp(nFlags, point); }
8.透明画刷
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { CClientDC dc(this); CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); CBrush *pOldBrush=dc.SelectObject(pBrush); dc.Rectangle(CRect(m_ptOrigin,point)); dc.SelectObject(pOldBrush); CView::OnLButtonUp(nFlags, point); }
9.绘制连续线条
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { m_bDraw=FALSE; CView::OnLButtonUp(nFlags, point); } void CDrawView::OnMouseMove(UINT nFlags, CPoint point) { CClientDC dc(this); if(m_bDraw==TRUE) { dc.MoveTo(m_ptOrigin); dc.LineTo(point); m_ptOrigin=point; } CView::OnMouseMove(nFlags, point); }
10.绘制扇形效果的线条
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { m_bDraw=FALSE; CView::OnLButtonUp(nFlags, point); } void CDrawView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CClientDC dc(this); CPen pen(PS_SOLID,1,RGB(255,0,0)); CPen *pOldPen=dc.SelectObject(&pen); if(m_bDraw==TRUE) { dc.SetROP2(R2_BLACK); dc.MoveTo(m_ptOrigin); //dc.LineTo(point); dc.LineTo(m_ptOld); //dc.MoveTo(m_ptOrigin); dc.MoveTo(m_ptOld); dc.LineTo(point); //m_ptOrigin=point; m_ptOld=point; } dc.SelectObject(pOldPen); CView::OnMouseMove(nFlags, point); }
相关文章推荐
- MFC基本图形的绘制(一)设备环境类CDC、画笔和画刷
- MFC学习笔记.day02续-CDC类,绘图区域,CPen画笔,画刷 CBrush,DC设备描述表
- 【转】MFC的运行机制 以及 MFC中的DC、CDC、HDC、句柄、设备上下文(整理)
- MFC画图(画线、画矩形、画刷画笔的使用)
- MFC里 显示设备上下文CClient dc(this) 和 CPaintDC dc(this)
- 再学 GDI+[30]: TGPPen - 用画刷定义的画笔
- MFC的运行机制 以及 MFC中的DC、CDC、HDC、句柄、设备上下文(整理)
- MFC画笔\画刷\加载位图\加载外部图片(LoadImage)\调色板\区域绘制、 复杂图像绘制等14.5.6
- MFC画图(画线、画矩形、画刷画笔的使用)
- MFC的运行机制 以及 MFC中的DC、CDC、HDC、句柄、设备上下文(整理)
- MFC中的DC、CDC、HDC、句柄、设备上下文的不同意思,适合初学者参考
- 设备上下文(DC)与内存设备上下文中的位图与画刷属性的一些零碎
- MFC画图(画线、画矩形、画刷画笔的使用)
- 猎豹MFC--画笔CPen和画刷CBrush
- MFC中设备描述符DC,CDC,HDC,CClientDC总结
- GdiPlus[26]: IGPPen: 用画刷建立画笔
- MFC的运行机制 以及 MFC中的DC、CDC、HDC、句柄、设备上下文(整理)
- MFC 绘图知识 画刷画笔 及各种图形
- MFC的运行机制 以及 MFC中的DC、CDC、HDC、句柄、设备上下文(整理) .
- MFC的运行机制 以及 MFC中的DC、CDC、HDC、句柄、设备上下文 [转]