using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class DesktopCapture {
[DllImport("user32.dll")]
private extern static IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
private extern static IntPtr GetDC(IntPtr windowHandle);
[DllImport("gdi32.dll")]
private extern static IntPtr GetCurrentObject(IntPtr hdc,
ushort objectType);
[DllImport("user32.dll")]
private extern static void ReleaseDC( IntPtr hdc );
const int OBJ_BITMAP = 7;
public static Bitmap Capture() {
IntPtr desktopWindow = GetDesktopWindow();
IntPtr desktopDC = GetDC( desktopWindow );
IntPtr desktopBitmap = GetCurrentObject(desktopDC, OBJ_BITMAP);
Bitmap desktopImage = Image.FromHbitmap( desktopBitmap );
ReleaseDC(desktopDC);
return desktopImage;
}
}
|