2 out of 4 rated this helpful - Rate this topic

GetDC function

Applies to: desktop apps only

The GetDC function retrieves a handle to a device context (DC) 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 DC. The device context is an opaque data structure, whose values are used internally by GDI.

The GetDCEx function is an extension to GetDC, which gives an application more control over how and whether clipping occurs in the client area.

Syntax

HDC GetDC(
  __in  HWND hWnd
);

Parameters

hWnd [in]

A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen.

Return value

If the function succeeds, the return value is a handle to the DC for the specified window's client area.

If the function fails, the return value is NULL.

Remarks

The GetDC function retrieves a common, class, or private DC depending on the class style of the specified window. For class and private DCs, GetDC leaves the previously assigned attributes unchanged. However, for common DCs, GetDC assigns default attributes to the DC each time it is retrieved. For example, the default font is System, which is a bitmap font. Because of this, the handle to a common DC returned by GetDC does not tell you what font, color, or brush was used when the window was drawn. To determine the font, call GetTextFace.

Note that the handle to the DC can only be used by a single thread at any one time.

After painting with a common DC, the ReleaseDC function must be called to release the DC. Class and private DCs do not have to be released. ReleaseDC must be called from the same thread that called GetDC. The number of DCs is limited only by available memory.

Examples

For an example, see Drawing with the Mouse.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Device Contexts Overview
Device Context Functions
GetDCEx
ReleaseDC
GetTextFace
GetWindowDC

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
just for default monitor
if you pass in NULL, it gets you a DC for the default monitor, see http://msdn.microsoft.com/en-us/library/dd144947(v=vs.85).aspx for details.  Except that apparently at least windows 7 with aero, it *can* capture from both monitors, just getting the sizes will be for the primary display if you use GetDeviceCaps with that DC.  GetDesktopWindow may also be useful.
Does not include window chrome
"The GetDC function retrieves a handle to a device context (DC) for the client area of a specified window".

See GetWindowDC in Painting and Drawing Reference instead, to include the window chrome in your operations like BitBlt.
little missout that can lead to wrong interpretations.
The GetDC function retrieves ALWAYS a DIFFERENT handle to a device context (DC) ...