GetDCEx

3.1

  HDC GetDCEx(hwnd, hrgnClip, fdwOptions)    
  register HWND hwnd; /* window where drawing will occur */
  HRGN hrgnClip; /* clipping region that may be combined */
  DWORD fdwOptions; /* device-context options */

The GetDCEx function retrieves the handle of a device context for the given window. The device context can be used in subsequent graphics device interface (GDI) functions to draw in the client area.

This function, which is an extension to the GetDC function, gives an application more control over how and whether a device context for a window is clipped.

Parameters

hwnd

Identifies the window where drawing will occur.

hrgnClip

Identifies a clipping region that may be combined with the visible region of the client window.

fdwOptions

Specifies how the device context is created. This parameter can be a combination of the following values:

Value Meaning

DCX_CACHE Returns a device context from the cache, rather than the OWNDC or CLASSDC window. Essentially overrides CS_OWNDC and CS_CLASSDC.
DCX_CLIPCHILDREN Excludes the visible regions of all child windows below the window identified by the hwnd parameter.
DCX_CLIPSIBLINGS Excludes the visible regions of all sibling windows above the window identified by the hwnd parameter.
DCX_EXCLUDERGN Excludes the clipping region identified by the hrgnClip parameter from the visible region of the returned device context.
DCX_INTERSECTRGN Intersects the clipping region identified by the hrgnClip parameter with the visible region of the returned device context.
DCX_LOCKWINDOWUPDATE Allows drawing even if there is a LockWindowUpdate call in effect that would otherwise exclude this window. This value is used for drawing during tracking.
DCX_PARENTCLIP Uses the visible region of the parent window, ignoring the parent window's WS_CLIPCHILDREN and WS_PARENTDC style bits. This value sets the device context's origin to the upper-left corner of the window identified by the hwnd parameter.
DCX_WINDOW Returns a device context corresponding to the window rectangle rather than the client rectangle.

Return Value

The return value is a handle of the device context for the specified window, if the function is successful. Otherwise, it is NULL.

Comments

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

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

In order to obtain a cached device context, an application must specify DCX_CACHE. If DCX_CACHE is not specified and the window is neither CS_OWNDC nor CS_CLASSDC, this function returns NULL.

See Also

BeginPaint, GetDC, GetWindowDC, ReleaseDC