Drawing3d documented Class Library

FeaturesW32.GetDC Method

The GetDC function retrieves a handle to a display 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 GetDCEx function is an extension to GetDC, which gives an application more control over how and whether clipping occurs in the client area.

[Visual Basic]
<PreserveSig> _
<DllImport(EntryPoint:="GetDC", CharSet:=CharSet.None, SetLastError:=True, ExactSpelling:=False, PreserveSig:=True, CallingConvention:=CallingConvention.StdCall, BestFitMapping:=False, ThrowOnUnmappableChar:=False, Value:="user32.dll")> _
<SuppressUnmanagedCodeSecurity> _
Public Shared Sub GetDC( _
   ByVal windowHandle As IntPtr _
[DllImport(EntryPoint="GetDC", CharSet=CharSet.None, SetLastError=True, ExactSpelling=False, PreserveSig=True, CallingConvention=CallingConvention.StdCall, BestFitMapping=False, ThrowOnUnmappableChar=False, Value="user32.dll")]
public static IntPtr GetDC(
   IntPtr windowHandle



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.

Windows NT/2000/XP: To get extended error information, call GetLastWin32Error.


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 for a common DC returned by GetDC does not tell you what font, color, or brush was used when the window was drawn.

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.

Windows 95/98/Me: There are only 5 common DCs available per thread, thus failure to release a DC can prevent other applications from accessing one.

See Also

FeaturesW32 Class | Drawing3d.OS.Windows Namespace | ReleaseDC