Tổng quan về lập trình GDI
Trang 11 Giơi thiêu
,
2005
2
,
p
3.1 lơp DC
Trang 2
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
Trang 3}
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 -
,
CBitmap -
Trang 4CFont -
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)
xxxTo
MoveTo
Trang 5LineTo
Polyline
Arc
ArcTo
PolyBezier
PolyBezierTo
(100, 200)
void CTestGDIView::OnDraw(CDC* pDC) {
pDC->MoveTo(10, 10);
pDC->LineTo(200, 200);
}
#include <math.h>
#define SEGMENTS 100
Trang 6#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 };
Trang 7POINT aPoint2[4] = { 120,100,50,350,250,200,500,40 };
pDC->PolyBezier (aPoint1, 4);
pDC->PolyBezier (aPoint2, 4);
}
Chord
Ellipse
Pie
Polygon
Rectangle
RoundRect
void CTestGDIView::OnDraw(CDC* pDC) {
Trang 8
pDC->Ellipse (0, 0, 150, 200); pDC->Rectangle (50, 50, 100, 150); }
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)
Trang 9{
CPen pen (PS_DASH, 4, RGB (255, 0, 0));
CPen* pOldPen = pDC->SelectObject (&pen); // pOldPen lưu
pDC->Ellipse (50, 50, 300, 200);
}
CBrush(
COLORREF crColor );
CBrush(
int nIndex, COLORREF crColor );
explicit CBrush(
CBitmap* pBitmap );
Trang 10void CTestGDIView::OnDraw(CDC* pDC) {
CBrush brush (HS_DIAGCROSS, RGB (255, 0, 0)); pDC->SelectObject (&brush);
pDC->Rectangle (0, 0, 100, 100);
}