1
Lp trình C trên Windows
Ví d và Bài tp (T4)
Nguyn Đức Hoàng H
Khoa CNTT Trường ĐHKHTN
Email: ndhha@fit.hcmuns.edu.vn
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 phi trong WM_PAINT
HDC GetDC( HWND hWnd);
int ReleaseDC( HWND hWnd,
HDC hDC // handle to DC );
Chn 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);