public static Bitmap GrabCurrentScreen(IntPtr hwnd)
{
Rect rc;
Rect client;
Point p;
p.x = 0; p.y = 0;
GetWindowRect(hwnd, out rc);
GetClientRect(hwnd, out client);
ClientToScreen(hwnd, out p);
if (rc.Width == 0 || rc.Height == 0)
return null;
rc.left = p.x;
rc.top = p.y;
rc.right = rc.left + client.Width;
rc.bottom = rc.top + client.Height;
Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
gfxBmp.CopyFromScreen(rc.left, rc.top, 0, 0, new Size(rc.Width, rc.Height), CopyPixelOperation.SourceCopy);
//gfxBmp.CopyFromScreen(client.left, client.top, 0, 0, new Size(client.Width, client.Height), CopyPixelOperation.SourceCopy);
gfxBmp.Dispose();
return bmp;
}