using System;
using System.Diagnostics;
using System.Drawing;
namespace ConsoleApplication1
{
class Program
{
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
static void Main(string[] args)
{
//ハンドルの取得
var targetProccess = Process.GetProcessesByName("devenv")[0];//ここでは最初の一つを対象にした
var handle = targetProccess.MainWindowHandle;
//保存対象の画像処理
var rec = new RECT();
var size = GetClientRect(handle, out rec);
var img = new Bitmap(rec.Right - rec.Left, rec.Bottom);
var memg = Graphics.FromImage(img);
IntPtr dc = memg.GetHdc();
PrintWindow(handle, dc, 0);
memg.ReleaseHdc(dc);
memg.Dispose();
//画像保存
img.Save("画像.png");
}
}
}