static Bitmap Win32CaptureDesktop() { SIZE size; IntPtr hBitmap; IntPtr hDC = Win32API.GetDC(Win32API.GetDesktopWindow()); IntPtr hMemDC = GDIAPI.CreateCompatibleDC(hDC); size.cx = Win32API.GetSystemMetrics (Win32API.SM_CXSCREEN); size.cy = Win32API.GetSystemMetrics (Win32API.SM_CYSCREEN); hBitmap = GDIAPI.CreateCompatibleBitmap(hDC, size.cx, size.cy); if (hBitmap != IntPtr.Zero) { IntPtr hOld = (IntPtr)GDIAPI.SelectObject (hMemDC, hBitmap); GDIAPI.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, GDIAPI.SRCCOPY); GDIAPI.SelectObject(hMemDC, hOld); GDIAPI.DeleteDC(hMemDC); Win32API.ReleaseDC(Win32API.GetDesktopWindow(), hDC); Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap); GDIAPI.DeleteObject(hBitmap); GC.Collect(); return(bmp); } return(null); }
public static long DeleteObject(System.IntPtr value) { return(GDIAPI.DeleteObject(value)); }