[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
<DllImport("user32.dll")> _
Private Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
End Function
The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common DC.
An application cannot use the ReleaseDC function to release a DC that was created by calling the CreateDC function; instead, it must use the DeleteDC function. ReleaseDC must be called from the same thread that called GetDC.
The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. It has no effect on class or private DCs.
Using managed DC functions for API's that require the DC work almost just as well as the API DC functions themselves.
For .NET Compact Framework, change user32.dll to coredll.dll.
See TextOut or GetTextExtentPoint for a sample of using DC's in C# managed code.
Graphics.GetHdc()
Graphics.ReleaseHdc()
8-5-06 Update by Gabriel T. Sharp (osirisgothra@hotmail.com)