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:
The key to accessing non-client area is GetWindowDC function, everything else is blitting as usual:
procedure TForm5.FormClick(Sender: TObject);
var
Bitmap: TBitmap;
DC: HDC;
FileName: string;
begin
Bitmap := TBitmap.Create;
try
Assert(HandleAllocated);
DC := GetWindowDC(Handle);
Win32Check(DC <> 0);
Bitmap.SetSize(Width, Height);
Win32Check(BitBlt(Bitmap.Canvas.Handle, 0, 0, Width, Height, DC, 0, 0, SRCCOPY));
FileName := Name + '.' + GraphicExtension(TBitmap);
Bitmap.SaveToFile(FileName);
ShellExecute(HWND_DESKTOP, nil, PChar(FileName), nil, nil, SW_NORMAL);
finally
ReleaseDC(Handle, DC);
Bitmap.Free;
end;
end;
For the second case of hidden (not painted!) window - see a comment from RRUZ.