Destination ist davon abhänig, was du mit dem Bild machen willst.
Wenn du es speichern willst, kannst du es in eine TBitmap-Instanz kopieren und dann speichern.
Delphi-Quellcode:
uses
SysUtils, Classes, Windows, Graphics;
...
function TakeScreenshot(FileName: PChar): Integer; stdcall;
var
Res: Integer;
DesktopDC: HDC;
DesktopImage: TBitmap;
DesktopCanvas: TCanvas;
begin
Res := -1;
DesktopDC := GetDC(0);
if (DesktopDC <> 0) then
begin
try
DesktopCanvas := TCanvas.Create;
try
DesktopImage := TBitmap.Create;
try
DesktopCanvas.Handle := DesktopDC;
DesktopImage.Width :=
DesktopCanvas.ClipRect.Right - DesktopCanvas.ClipRect.Left;
DesktopImage.Height :=
DesktopCanvas.ClipRect.Bottom - DesktopCanvas.ClipRect.Top;
if (BitBlt(
DesktopImage.Canvas.Handle, 0, 0, DesktopImage.Width, DesktopImage.Height,
DesktopCanvas.Handle, 0, 0,
SRCCOPY
)
) then
begin
DesktopImage.SaveToFile(FileName);
Res := 0;
end;
finally
DesktopImage.Free;
end;
finally
DesktopCanvas.Free;
end;
finally
ReleaseDC(0, DesktopDC);
end;
end
else
Res := -2;
Result := Res;
end;
exports
TakeScreenshot;