I found some code on the web which grabs the current window and copies it into a bitmap. I’ve included the pertinent bit below. Currently it copies the client area, but I’d like to get the frame as well. Is there a way to get the handle of that? So I’d like to snapshot the entire window including maximise button, control button, etc.
// Capture snapshot of the form...
if (base.IsHandleCreated)
{
//
// Get DC of the form...
IntPtr srcDc = GetDC(Handle);
//
// Create bitmap to store image of form...
var bmp = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
//
// Create a GDI+ context from the created bitmap...
using (Graphics g = Graphics.FromImage(bmp))
{
//
// Copy image of form into bitmap...
IntPtr bmpDc = g.GetHdc();
BitBlt(bmpDc, 0, 0, bmp.Width, bmp.Height, srcDc, 0, 0, 0x00CC0020 /* SRCCOPY */);
Just use the form’s DrawToBitmap() method:
Graphics.CopyFromScreen() is another way, similar to what you’re doing now. It actually copies the image from the screen rather than asking the form to draw itself into a bitmap. With the same disadvantage, the form needs to be visible.