Professional Documents
Culture Documents
3.text Output
3.text Output
Introduction
Painting and Repainting
GDI
Introduction
The user resizes the window (if the window class style
has the CS_HREDRAW and CW_VREDRAW bits set).
GetUpdateRect
BeginPaint
ValidateRect
An Introduction to GDI
To paint the client area of your window, we use Windows
Graphics Device Interface (GDI) functions.
With TextOut,
the color of the text,
the color of the text background,
font for the text to be displayed
The Device Context
When a program needs to paint, it must first
obtain a handle to a device context.
The program may then use GDI functions, such as TextOut, that
require the handle to the device context.
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
[use GDI functions]
EndPaint (hwnd, &ps) ;
return 0 ;
The Paint Information Structure
Windows maintains a paint information structure
for each window.
typedef struct tagPAINTSTRUCT
{
HDC hdc ;
BOOL fErase ;
RECT rcPaint ;
BOOL fRestore ;
BOOL fIncUpdate ;
BYTE rgbReserved[32] ;
} PAINTSTRUCT ;
The Paint Information Structure
wndclass.hbrBackground = (HBRUSH)
GetStockObject (WHITE_BRUSH) ;
The boundaries of the invalid
rectangle.
Getting a Device Context Handle:
Method Two
case WM_CREATE:
hdc = GetDC (hwnd) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cyChar = tm.tmHeight +
tm.tmExternalLeading ;
ReleaseDC (hwnd, hdc) ;
return 0 ;
Use of Textout
int iLength ;
TCHAR szBuffer [40] ;
[ other program lines ]
iLength = wsprintf (szBuffer, TEXT ("The
sum of %i and %i is %i"), iA, iB, iA + iB) ;
TextOut (hdc, x, y, szBuffer, iLength) ;
Combine the two statements into one:
TextOut (hdc, x, y, szBuffer, wsprintf
(szBuffer, TEXT ("The sum of %i and %i is
%i"),iA, iB, iA + iB)) ;