1 / 11

GDI 画图进阶

GDI 画图进阶. CMemDC. Memdc.h. Application to use CMemDC: 1. Add the file memdc.h in your project. 2. Add the line #include " memdc.h " to stdafx.h. 3. Add a windows message handler for WM_ERASEBKGND . BOOL CExampleView::OnEraseBkgnd(CDC* pDC) { //return CView::OnEraseBkgnd(pDC);

gladys
Download Presentation

GDI 画图进阶

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GDI画图进阶

  2. CMemDC • Memdc.h

  3. Application to use CMemDC: • 1. Add the file memdc.h in your project. • 2. Add the line #include "memdc.h" to stdafx.h. • 3. Add a windows message handler for WM_ERASEBKGND. • BOOL CExampleView::OnEraseBkgnd(CDC* pDC) • { • //return CView::OnEraseBkgnd(pDC); • return FALSE; • } • 4. Change your OnDraw code to the following: • void CExampleView::OnDraw(CDC* dc) • { • CMemDC pDC(dc); • CExampleDoc* pDoc = GetDocument(); • ASSERT_VALID(pDoc); • // TODO: add draw code for native data here - use pDC • //as the device context to draw to • }

  4. 刷新窗口 • 发出消息WM_PAINT,激发OnPaint() and OnDraw() • Invalidate();

  5. GDIUtils.h and GDIUtils.cpp • 封装好的GDI画图类

  6. 定义CPen • Cpen pen( PS_SOLID, 2, RGB(0,0,255) ); • CGDISelectObject<CPen> tmpPen(pDC, &pen); • Or • Cpen pen(PS_NULL, 2, RGB(0,0,255) ); • CGDISelectObject<CPen> tmpPen(pDC, &pen);

  7. 定义CBrush • CBrush brush(RGB( 255,0,0 ) ); • CGDISelectObject<CBrush> tmpBrush(pDC, &brush); • Or • CBrush brush(HS_CROSS, RGB( 255,0,0 ) ); • CGDISelectObject<CBrush> tmpBrush(pDC, &brush); • Or • pDC->SelectStockObject( NULL_BRUSH );

  8. Dialog窗口

  9. CColorDialog • void CMiniDrawView::OnButtonFilledColor() • { • CColorDialog dlg; • if (dlg.DoModal() != IDOK) • return; • m_SelectedPolygons.SetFilledColor( dlg.GetColor() ); • Invalidate(); • }

  10. CFileDialog • void CMiniDrawView::OnButtonSaveToFile() • { • char szFilter[] = "WF Files (*.ply)|*.ply||"; • CFileDialog dlg(false,"ply","*.ply", • OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,this); • if(dlg.DoModal()==IDOK) • { • m_SelectedPolygons.SaveToFile(dlg.GetFileName().GetBuffer(128)); • } • }

  11. 自定义Dialog • Cedit • …

More Related