Share via


CWnd::GetWindowDC

Retrieves the display context for the entire window, including caption bar, menus, and scroll bars.

CDC* GetWindowDC( );

Return Value

Identifies the display context for the given window if the function is successful; otherwise NULL.

The returned pointer may be temporary and should not be stored for later use. ReleaseDC should be called once for each successful call to GetWindowDC.

Remarks

A window display context permits painting anywhere in CWnd, since the origin of the context is the upper-left corner of CWnd instead of the client area.

Default attributes are assigned to the display context each time it retrieves the context. Previous attributes are lost.

GetWindowDC is intended to be used for special painting effects within the CWnd nonclient area. Painting in nonclient areas of any window is not recommended.

The GetSystemMetrics Windows 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 member function must be called to release the display context. Failure to release the display context will seriously affect painting requested by applications due to limitations on the number of device contexts that can be open at the same time.

Requirements

Header: afxwin.h

See Also

Reference

CWnd Class

Hierarchy Chart

GetSystemMetrics

CWnd::ReleaseDC

GetWindowDC

CWnd::GetDC

CWindowDC Class

Concepts

CWnd Members