Link to home
Start Free TrialLog in
Avatar of dluedi
dluedi

asked on

Snapshot of desktop

How can I make a snapshot of the desktop with Delphi?
Avatar of DrDelphi
DrDelphi

This is getting to be my favorite question! <g>

You could download my TScreenGrab component from www.drdelphi.com OR

procedure TForm1.Button1Click(Sender: TObject);
begin
grabdesktoprect(rect(0,0,Screen.width,Screen.height),'C:\windows\desktop\test.bmp');
end;

function TForm1.GrabDesktopRect(rect: Trect; Fname: string): Boolean;
var tempbmp:Tbitmap;
    tempcanvas:Tcanvas;
begin
    tempbmp:=TBitmap.create;
    with tempbmp do
    begin
      height:=rect.bottom-rect.top;
      width:=rect.right-rect.left;
    end;
    tempcanvas:=TCanvas.create;
    TempCanvas.handle:= GetWindowDc(GetDeskTopwindow);
    tempbmp.Canvas.CopyRect(rect,tempcanvas,rect);
    tempbmp.savetofile(fname);
    tempbmp.Free;
    TempCanvas.free;
end;

end.


Your choice.

Good luck!!

ASKER CERTIFIED SOLUTION
Avatar of f15iaf
f15iaf

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial