
2
Graphics Device Interface
(GDI)

3
HDC
WM_PAINT
•HDC BeginPaint( HWND hwnd, // input
LPPAINTSTRUCT lpPaint // output );
•BOOL EndPaint( HWND hWnd,
PAINTSTRUCT*lpPaint );
Không phải trong WM_PAINT
•HDC GetDC( HWND hWnd);
•int ReleaseDC( HWND hWnd,
HDC hDC // handle to DC );
Chọn các đối tượng vẽ vào trong DC
•HGDIOBJ SelectObject( HDC hdc, HGDIOBJ hgdiobj);

4
HPEN
•HPEN CreatePen( int fnPenStyle,
int nWidth,
COLORREF crColor);
•BOOL DeleteObject( HGDIOBJ hObject);
•Ví dụ:
hdc = BeginPaint(hWnd, &ps);
hPen = CreatePen(PS_SOLID,2,0);
hOld = SelectObject(hdc,hPen);
MoveToEx(hdc,100,200,NULL);
LineTo(hdc,200,100);
SelectObject(hdc,hOld);
DeleteObject(hPen);
EndPaint(hWnd, &ps);

5
HBRUSH
•CreateBrushIndirect: Creates a brush with a specified style,
color, and pattern
•CreateDIBPatternBrushPt: Creates a brush with the pattern
from a DIB
•CreateHatchBrush: Creates a brush with a hatch pattern and
color
•CreatePatternBrush: Creates a brush with a bitmap pattern
•CreateSolidBrush: Creates a brush with a solid color
•Ví dụ:
hBr = CreateSolidBrush(255);
hOldBr = SelectObject(hdc,hBr);
Rectangle(hdc,0,0,400,200);
…


