Lecture 2: Windows Basics - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Lecture 2: Windows Basics

Description:

Invalid Rectangle: Clipping Region for hdc obtained by BeginPaint/EndPaint. ... That is, clipping region is the client area of window. Does not validate any ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 19
Provided by: phi140
Category:

less

Transcript and Presenter's Notes

Title: Lecture 2: Windows Basics


1
Client Area of Window Everything except title
bar, window edge, scrollbars.
Client Area
2
Invalid 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)
4
Invalid Rectangle
5
Invalid Region
Invalid Region
6
Invalid Rectangle Smallest rectangle the covers
all invalid regions.
(Does not include title bar and SB)
7
WM_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.

8
Device 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.

9
Obtaining 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.

10
typedef struct tagPAINTSTRUCT HDC hdc
BOOL fErase //Background needs erasing?
RECT rcPaint // Coords of invalid rectangle
. // Other fields. PAINTSTRUCT
11
Invalid Rectangle Clipping Region for hdc
obtained by BeginPaint/EndPaint.
(Does not include title bar and SB)
12
A 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.

13
HDC returned by GetDC/ReleaseDC has a clipping
region equal to the entire client area of the
window.
Client Area
14
A Couple of Bad Ideas
switch(message) case WM_PAINT hdc
GetDC(hwnd) ReleaseDC(hwnd, hdc)
return 0
15
switch(message) case WM_PAINT return 0

16
One approach that will work
switch(message) case WM_PAINT hdc
GetDC(hwnd) . ReleaseDC(hwnd,
hdc) ValidateRect(hwnd, NULL)
return 0
17
InvalidateRect (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)
Write a Comment
User Comments (0)
About PowerShow.com