Title: Lecture 2: Windows Basics
1Client Area of Window Everything except title
bar, window edge, scrollbars.
Client Area
2Invalid Rectangle
- Smallest rectangle that covers all invalid areas
called invalid rectangle. Causes WM_PAINT message
to be generated. - Continue to be generated until invalid rectangle
becomes validated. - BeginPaint(hwnd, ps)
- EndPaint(hwnd, ps)
-
- Treat as pair. Validates invalid rectangle.
3(No Transcript)
4Invalid Rectangle
5Invalid Region
Invalid Region
6Invalid Rectangle Smallest rectangle the covers
all invalid regions.
(Does not include title bar and SB)
7WM_PAINT Message
- Windows does not save contents of window.
- Generates WM_PAINT message when any part of the
window becomes invalid. - When previously hidden area becomes visible.
- When user resizes window (and class style set
with CS_HREDRAW CS_VREDRAW). - Application calls
- InvalidateRect, InvalidateWindow, ScrollWindow,
ScrollDC.
8Device Context
- Hardware device and device driver.
- Application gets a handle to a device context.
- Must obtain hdc before writing text or graphics
to window. - Device context determines
- Area of window accessible to application.
- Default graphical attributes
- Text size and color.
- Text font.
9Obtaining Handle to DC
- hdc BeginPaint(hwnd, ps)
- Actions
- 1. Validates any invalid areas.
- 2. Erases window background (Most of the
time). - 3. Fills in fields of ps.
- 4. CD restricts outputting to invalid
rectangle. -
10typedef struct tagPAINTSTRUCT HDC hdc
BOOL fErase //Background needs erasing?
RECT rcPaint // Coords of invalid rectangle
. // Other fields. PAINTSTRUCT
11Invalid Rectangle Clipping Region for hdc
obtained by BeginPaint/EndPaint.
(Does not include title bar and SB)
12A Different Device Context
- hdc GetDC(hwnd)
-
- ReleaseDC(hwnd, hdc)
- Allows application to write anywhere within the
client area. That is, clipping region is the
client area of window. - Does not validate any invalid areas.
-
13HDC returned by GetDC/ReleaseDC has a clipping
region equal to the entire client area of the
window.
Client Area
14A Couple of Bad Ideas
switch(message) case WM_PAINT hdc
GetDC(hwnd) ReleaseDC(hwnd, hdc)
return 0
15switch(message) case WM_PAINT return 0
16One approach that will work
switch(message) case WM_PAINT hdc
GetDC(hwnd) . ReleaseDC(hwnd,
hdc) ValidateRect(hwnd, NULL)
return 0
17InvalidateRect (hwnd, NULL, TRUE)
hwnd Handle to window. NULL Invalidate entire
client area of the window. Alternatively
InvalidateRect(hwnd, rect, TRUE) TRUE/FALSE
Erase/Do not erase the background of the window.
18- TextOut (hdc, x, y, buf, length)