GetWindowDC

  HDC GetWindowDC(hwnd)    
  HWND hwnd; /* handle of window */

This function retrieves the display context for the entire window, including caption bar, menus, and scroll bars. A window display context permits painting anywhere in a window, including the caption bar, menus, and scroll bars, since the origin of the context is the upper-left corner of the window instead of the client area.

GetWindowDC assigns default attributes to the display context each time it retrieves the context. Previous attributes are lost.

Parameters

hwnd

Identifies the window whose display context is to be retrieved.

Return Value

The return value identifies the display context for the given window if the function is successful. Otherwise, it is NULL.

Comments

The GetWindowDC function is intended to be used for special painting effects within a window's nonclient area. Painting in nonclient areas of any window is not recommended.

The GetSystemMetrics function can be used to retrieve the dimensions of various parts of the nonclient area, such as the caption bar, menu, and scroll bars.

After painting is complete, the ReleaseDC function must be called to release the display context. Failure to release a window display context will have serious effects on painting requested by applications.

See Also

GetSystemMetrics, ReleaseDC, GetDC