unit Unit1;
interface
uses
Jpeg,{GIFimage,}Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject
var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
hotkeyid :integer;
procedure WMhotkeyhandle(var msg:Tmessage);
message wm_hotkey;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Wmhotkeyhandle
(var msg:Tmessage);
begin
if msg.LParamHi=vk_f11 then
begin
msg.Result:=1;
button1.Click;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Bitmap:TBitmap;
Jpeg: TJpegImage;
Handles: HWnd;
Rect: TRect;
ScreenDC: HDC;
begin
Handles := GetForegroundWindow ( );
ScreenDC := GetWindowDC ( Handles );
Bitmap := TBitmap.Create;
GetWindowRect ( Handles, Rect );
Bitmap.Width := Rect.Right - Rect.Left;
Bitmap.Height := Rect.Bottom - Rect.Top;
BitBlt(Bitmap.Canvas.Handle,0,0,Bitmap.Width ,Bitmap.Height,ScreenDC,0,0,SRCCOPY );
ReleaseDC ( Handles, ScreenDC );
Jpeg:= TJpegImage.Create;
Jpeg.Assign(Bitmap);
Jpeg.SaveToFile(ExtractFIlePath(Application.ExeName)+'jpeg.jpg');
jpeg.free;
Bitmap.SaveToFile(ExtractFIlePath(Application.ExeName)+'bmp.bmp');
Bitmap.Free;
//end;
showmessage('捕捉屏幕得到的图象文件被保存在如下目录下'#13+ExtractFIlePath(Application.ExeName));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HotKeyId := GlobalAddAtom('MyHotKey') - $C000;
registerhotkey(handle,hotkeyid,0, vk_f11)
//这里注册
end;
procedure TForm1.FormClose(Sender: TObject
var Action: TCloseAction);
begin
unregisterhotkey(handle,hotkeyid);
DeleteAtom(HotKeyID);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//
end;
end.
//试试看吧,我这能捕捉,按F11键捕捉。