I want to paint the whole form including its caption bar and frame on a TBitmap
object.
GetFormImage
is cool, but it has two problems:
Here is a little function that I've used that you might find useful.
Edit: Oops I didn't fully read the question. This probably doesn't work with a hidden window, but I'm not sure anything would unless the form could draw the frame itself, but it doesn't, the OS does.
function GetScreenShot(const aWndHandle:THandle; AeroAware:boolean=true):TBitmap;
var
wWindow: HDC;
wRect : TRect;
wDesktop : THandle;
begin
Result := TBitmap.Create;
try
if AeroAware then
wDesktop := GetDesktopWindow
else
wDesktop := aWndHandle;
wWindow := GetDC(wDesktop);
try
Result.PixelFormat := pf32bit;
GetWindowRect(aWndHandle, wRect);
Result.Width := wRect.Right-wRect.Left;
Result.Height := wRect.Bottom-wRect.Top;
if AeroAware then
BitBlt(Result.Canvas.Handle, 0, 0, Result.Width, Result.Height, wWindow, wRect.Left, wRect.Top, SRCCOPY)
else
BitBlt(Result.Canvas.Handle, 0, 0, Result.Width, Result.Height, wWindow, 0, 0, SRCCOPY);
Result.Modified := True;
finally
ReleaseDC(wDesktop, wWindow);
end;
except
Result.Free;
Result := nil;
end;
end;