public static Image CaptureWindow(IntPtr handle) { var windowDC = User32.GetWindowDC(handle); var rect = new RECT(); User32.GetWindowRect(handle, ref rect); var nWidth = rect.right - rect.left; var nHeight = rect.bottom - rect.top; var hDC = CreateCompatibleDC(windowDC); var hObject = CreateCompatibleBitmap(windowDC, nWidth, nHeight); var ptr4 = SelectObject(hDC, hObject); BitBlt(hDC, 0, 0, nWidth, nHeight, windowDC, 0, 0, 0xcc0020); SelectObject(hDC, ptr4); DeleteDC(hDC); User32.ReleaseDC(handle, windowDC); Image image = Image.FromHbitmap(hObject); DeleteObject(hObject); return image; }
public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);