The GetDCEx function retrieves a handle to a display device context for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the device context.
This function is an extension to the GetDC function, which gives an application more control over how and whether clipping occurs in the client area.
HDC GetDCEx(
HWND hWnd, // handle of window
HRGN hrgnClip, // handle of clip region
DWORD flags // device-context creation flags
);
Windows 98, Windows NT 5.0 and later: If this parameter is NULL, GetDCEx retrieves the device context for the primary display monitor. To get the device context for other display monitors, use the EnumDisplayMonitors and CreateDC functions.
Value | Meaning |
---|---|
DCX_WINDOW | Returns a device context corresponding to the window rectangle rather than the client rectangle. |
DCX_CACHE | Returns a device context from the cache, rather than the OWNDC or CLASSDC window. Essentially overrides CS_OWNDC and CS_CLASSDC. |
DCX_PARENTCLIP | Uses the visible region of the parent window. The parent's WS_CLIPCHILDREN and CS_PARENTDC style bits are ignored. The device context origin is set to the upper-left corner of the window identified by hWnd. |
DCX_CLIPSIBLINGS | Excludes the visible regions of all sibling windows above the window identified by hWnd. |
DCX_CLIPCHILDREN | Excludes the visible regions of all child windows below the window identified by hWnd. |
DCX_NORESETATTRS | Does not reset the attributes of this device context to the default attributes when this device context is released. |
DCX_LOCKWINDOWUPDATE | Allows drawing even if there is a LockWindowUpdate call in effect that would otherwise exclude this window. Used for drawing during tracking. |
DCX_EXCLUDERGN | The clipping region identified by hrgnClip is excluded from the visible region of the returned device context. |
DCX_INTERSECTRGN | The clipping region identified by hrgnClip is intersected with the visible region of the returned device context. |
DCX_VALIDATE | When specified with DCX_INTERSECTUPDATE, causes the device context to be completely validated. Using this function with both DCX_INTERSECTUPDATE and DCX_VALIDATE is identical to using the BeginPaint function. |
If the function succeeds, the return value is the handle of the device context for the specified window.
If the function fails, the return value is NULL. An invalid value for the hWnd parameter will cause the function to fail.
Windows NT: To get extended error information, call GetLastError.
Unless the display device context belongs to a window class, the ReleaseDC function must be called to release the device context after painting. Because 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.
The function returns a device context belonging to the window's class if CS_CLASSDC, CS_OWNDC or CS_PARENTDC was specified as a style in the WNDCLASS structure when the class was registered.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winuser.h.
Import Library: Use user32.lib.
Device Contexts Overview, Device Context Functions, BeginPaint, GetWindowDC, ReleaseDC, WNDCLASS