Tổng quan về lập trình gdi

Tổng quan về lập trình gdi 1.giới thiệu 2.gdi là gì 3.các lớp cơ bản 3.1.các lớp dc 3.2.các lớp đối tượng vẽ 4.ví dụ 4.1.tạo project 4.2.xử lý trên từng pixcel 4.3.vẽ đoạn thẳng và đường cong 4.4.vẽ hình elip, hình cong 4.5.chọn pen 4.6.chọn brush

pdf10 trang | Chia sẻ: tlsuongmuoi | Lượt xem: 2291 | Lượt tải: 0download
Bạn đang xem nội dung tài liệu Tổng quan về lập trình gdi, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
1 Giơi thiêu , . 2005. 2 , . p 1 - . 2 - . 3 - . 4 - . 3 ơp cơ ban 3.1 lơp DC . . . CPaintDC 1 ( OnPaint) CClientDC ( OnPaint) CWindowDC CMetaFileDC CDC - sau CDC* pDC = GetDC (); // Do some drawing ReleaseDC (pDC); CPaintDC - void CMyView::OnPaint() { CPaintDC dc(this); dc.TextOut(0, 0, "for the display, not the printer"); OnDraw(&dc); // stuff that's common to display and // printer 1 menu } CClientDC - void CMainWindow::OnLButtonDown (UINT nFlags, CPoint point) { CRect rect; GetClientRect (&rect); CClientDC dc (this); dc.MoveTo (rect.left, rect.top); dc.LineTo (rect.right, rect.bottom); dc.MoveTo (rect.right, rect.top); dc.LineTo (rect.left, rect.bottom); } CWindowDC - . 3.2 ơ ng ,... CBitmap - . . CBrush - . CFont - c,... CPen - ,... CPalette - . CRgn - ,... 4 4.1 o project . 4.2 X  COLORREF SetPixel(int x, int y, COLORREF color)  COLORREF SetPixel(POINT point, COLORREF color)  COLORREF GetPixel(int x, int y)  COLORREF GetPixel(POINT point) 4.3 n thă ương cong xxxTo . MoveTo LineTo Polyline PolylineTo v Arc ArcTo PolyBezier PolyBezierTo . (100, 200) void CTestGDIView::OnDraw(CDC* pDC) { ... pDC->MoveTo(10, 10); pDC->LineTo(200, 200); } #include #define SEGMENTS 100 #define PI 3.14159 void CTestGDIView::OnDraw(CDC* pDC) { ... CRect rect; GetClientRect (&rect); int nWidth = rect.Width (); int nHeight = rect.Height (); CPoint aPoint[SEGMENTS]; for (int i=0; i<SEGMENTS; i++) { aPoint[i].x = (i * nWidth) / SEGMENTS; aPoint[i].y = (int) ((nHeight / 2) * (1 - (sin ((2 * PI * i) / SEGMENTS)))); } pDC->Polyline (aPoint, SEGMENTS); } void CTestGDIView::OnDraw(CDC* pDC) { ... POINT aPoint1[4] = { 120,100,120,200,250,150,500,40 }; POINT aPoint2[4] = { 120,100,50,350,250,200,500,40 }; pDC->PolyBezier (aPoint1, 4); pDC->PolyBezier (aPoint2, 4); } 4.4 ư nhâ Chord Ellipse Pie Polygon Rectangle RoundRect void CTestGDIView::OnDraw(CDC* pDC) { ... pDC->Ellipse (0, 0, 150, 200); pDC->Rectangle (50, 50, 100, 150); } 4.5 n pen . CPen( int nPenStyle, int nWidth, COLORREF crColor ); CPen( int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL ); V void CTestGDIView::OnDraw(CDC* pDC) { ... CPen pen (PS_DASH, 4, RGB (255, 0, 0)); CPen* pOldPen = pDC->SelectObject (&pen); // pOldPen lưu pDC->Ellipse (50, 50, 300, 200); } 4.6 n brush CBrush( COLORREF crColor ); CBrush( int nIndex, COLORREF crColor ); explicit CBrush( CBitmap* pBitmap ); void CTestGDIView::OnDraw(CDC* pDC) { ... CBrush brush (HS_DIAGCROSS, RGB (255, 0, 0)); pDC->SelectObject (&brush); pDC->Rectangle (0, 0, 100, 100); }

Các file đính kèm theo tài liệu này:

  • pdfTổng quan về lập trình gdi.pdf
Tài liệu liên quan