截图:截取当前程序的界面,并保存到bmp图片中。

直接上代码:

 

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Clipbrd;

type
TForm1
= class(TForm)
btn1: TButton;
dlgSave1: TSaveDialog;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
bmp:TBitmap;
MyRect:TRect;
Myrect2:TRect;
canvas:TCanvas;
DC:HDC;
b:TPoint;
aa:TPoint;
begin
ShowMessage(
'---------------');
bmp :
= TBitmap.Create;
bmp.Width :
= Form1.Width;
bmp.Height :
= form1.Height;
MyRect :
= Rect(Form1.Left,Form1.Top,bmp.Width+Form1.Left,bmp.height+Form1.Top);
Myrect2 :
=Rect(0,0,bmp.Width,bmp.height);
DC :
= GetDC(0);
Canvas :
= TCanvas.Create;
Canvas.Handle :
= DC;
bmp.Canvas.CopyRect(MyRect2,Canvas,MyRect);
Clipboard.Assign(bmp);
if dlgSave1.Execute then
bmp.SaveToFile(dlgSave1.FileName
+ '.bmp');
Canvas.Free;
ReleaseDC(
0,DC);
bmp.Free;


end;

end.

 

posted @ 2010-05-10 22:22  Delcpp  阅读(1399)  评论(1编辑  收藏  举报