Screenshot

From Free Pascal wiki
Revision as of 22:59, 22 January 2022 by Alextp (talk | contribs) (Created page with "The example code creates the screenshot inside the TBitmap object. You can then save this bitmap to a file. ==Example 1== Code from forum user ''fripster''. It supports Windo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The example code creates the screenshot inside the TBitmap object. You can then save this bitmap to a file.

Example 1

Code from forum user fripster. It supports Windows and Linux.

procedure TakeScreenShot(b: Graphics.TBitmap);
{$IFDEF WINDOWS}
var
  ScreenDC: HDC;
begin
  b.Width:= Screen.DesktopWidth;
  b.Height:= Screen.DesktopHeight;
  b.Canvas.Brush.Color:= clWhite;
  b.Canvas.FillRect(0, 0, b.Width, b.Height);
  ScreenDC:= GetDC(GetDesktopWindow);
  BitBlt(b.Canvas.Handle, 0, 0, b.Width, b.Height, ScreenDC, Screen.DesktopLeft, Screen.DesktopTop, SRCCOPY);
  ReleaseDC(0, ScreenDC);
end;
{$ENDIF}
 
{$IFDEF LINUX}
var
  ScreenDC: HDC;
begin
  ScreenDC:= GetDC(0);
  b.LoadFromDevice(ScreenDC);
  ReleaseDC(0,ScreenDC);
end;
{$ENDIF}