|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Retrieves the display context for the entire window, including caption bar, menus, and scroll bars.
CDC* GetWindowDC( );
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.
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.