GetDCEx

  HDC GetDCEx(hwnd, hrgnClip, flags);    
  HWND hwnd; /* window where drawing will occur */
  HRGN hrgnClip; /* clip region that may be combined */
  DWORD flags; /* specifies how DC is created */

The GetDCEx function retrieves the handle of a display context for the specified window. The display context can be used in subsequent GDI functions to draw in the client area.

This function is an extension to the GetDC function that gives an application more control over how and whether a DC for a window is clipped.

Parameters

hwnd

Identifies the window where drawing will occur.

hrgnClip

Specifies a clip region that may be combined with the visible region of the client window.

flags

Specifies how the DC is created. This parameter may be some combination of the following values:

Value Meaning

DCX_WINDOW Returns a DC corresponding to the window rectangle rather than the client rectangle.
DCX_CACHE Returns a DC from the cache, rather than the OWNDC or CLASSDC window. Essentially overrides CS_OWNDC and CS_CLASSDC.
DCX_DEFAULTCLIP Returns a DC using the default clipping flags specified by WS_CLIPCHILDREN, WS_CLIPSIBLINGS, and WS_PARENTDC.
DCX_PARENTCLIP Use the visible region of the parent window. The parent's WS_CLIPCHILDREN and WS_PARENTDC style bits are ignored. The DC origin is set to the top left corner of the the window specified by the hwnd parameter.
DCX_CLIPSIBLINGS Exclude the visible regions of all sibling windows above the window specified by the hwnd parameter.
DCX_CLIPCHILDREN Exclude the visible regions of all child windows below the window specified by the hwnd parameter.
DCX_NORESETATTRS Do not reset the attributes of this DC to the default attributes when this DC is released.
DCX_NORECOMPUTE If an exact match in the cache is not found, return NULL rather than creating a new DC. When used with DCX_NORESETATTRS, this gives applications a way to determine whether they need to reselect any special attributes.
DCX_LOCKWINDOWUPDATE Allow drawing even if there is a LockWindowUpdate() call in effect that would otherwise exclude this window. Used for drawing during tracking.
DCX_EXCLUDERGN The clip region specified by the hrgnClip is excluded from the visible region of the returned DC.
DCX_INTERSECTRGN The clip region specified by the hrgnClip parameter is intersected with the visible region of the returned DC.
DCX_VALIDATE When specified with DCX INTERSECTUPDATE, this flag causes the DC to be completely validated. Using this function with both DCX_INTERSECTUPDATE and DCX_VALIDATE is identical to using the BeginPaint function.

Return Value

The return value identifies the display context for the specified window if the function is successful. The return value is NULL if the hwnd parameter is invalid.

Comments

Unless the display context belongs to a window class, the ReleaseDC function must be called to release the context after painting. Since only five common display contexts are available at any given time, failure to release a display context can prevent other applications from accessing a display context.

A display context belonging to the window's class is returned by the GetDC function if CS_CLASSDC, CS_OWNDC or CS_PARENTDC was specified as a style in the WNDCLASS structure when the class was registered.

See Also

BeginPaint, GetDC, GetWindowDC, ReleaseDC