GetDC (user32)
Last changed: -189.172.115.110

.
Summary
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.

C# Signature:

[DllImport("user32.dll")]
static extern IntPtr GetDC(HandleRef hWnd);

VB Signature:

Private Declare Function GetDC Lib "user32" (ByVal hWnd As IntPtr) As IntPtr

VB.NET Signature:

<DllImport("User32.dll", EntryPoint:="GetDC", _
  CallingConvention:=CallingConvention.StdCall, _
  CharSet:=CharSet.Auto, exactspelling:=True)> _
Public Shared Function GetDC(ByVal hwnd As IntPtr) As Int32
End Function

User-Defined Types:

None.

Notes:

Given the level of transparency provided by the System.Drawing.Graphics class, it is probably better to use that instead of GetDC.

Remember, if you use GetDC manually without the Graphics class, you must call ReleaseDC.

This method can also be declared using an IntPtr instead of a HandleRef. Using a HandleRef ensures that the window will not be destroyed/GCed while the function is executing.

Tips & Tricks:

To get the DC for a specific display monitor, use the EnumDisplayMonitors and CreateDC functions.

Sample Code:

Please add some!

Alternative Managed API:

System.Drawing.Graphics.FromHwnd(IntPtr hwnd)

Documentation
GetDC on MSDN