[DllImport("user32.dll")]
public static extern bool PrintWindow(
IntPtr hwnd, // Window to copy,Handle to the window that will be copied.
IntPtr hdcBlt, // HDC to print into,Handle to the device context.
UInt32 nFlags // Optional flags,Specifies the drawing options. It can be one of the following values.
);
//传入窗口句柄,获取该窗口的图像信息
private Image GetWindowImage(IntPtr windownHandle)
{
Control control =Control.FromHandle(windownHandle);
Bitmap image = new Bitmap(control.Width, control.Height);
Graphics gp = Graphics.FromImage(image);
IntPtr dc = gp.GetHdc();
PrintWindow(windownHandle, dc, 0);
gp.ReleaseHdc();
gp.Dispose();
return image;
}