TForm1 = class(TForm)
ScrollBox1: TScrollBox;
Image1: TImage;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
hotkey:Integer;
procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;
procedure GetActiveWndImg;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.GetActiveWndImg;
var C:TCanvas; b:TBitmap; H:HDC; R:TRect; hand:THandle;
p:TPoint;
begin
B:=TBitmap.Create;
C:=TCanvas.Create;
GetCurSorPos(P);
Hand:= WindowFromPoint(P);
if hand=0 then exit;
H:=GetWindowDC(Hand);
try
GetWindowRect(hand,R);
B.Width:=R.Right-R.Left;
B.Height:=R.Bottom-R.Top;
C.Handle:=H;
B.Canvas.CopyRect(Rect(0,0,B.Width,B.Height),C
,Rect(0,0,B.Width,B.Height));
Image1.Picture.Bitmap.Assign(B);
finally
C.Free;
B.Free;
ReleaseDC(Hand, H);
end;
end;
procedure TForm1.HotKeyDown(var Msg: Tmessage);
begin
if (Msg.LParamHi = VK_SPACE)and (Msg.LParamLo=MOD_CONTROL) then
GetActiveWndImg;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
hotkey:=0;
if not RegisterHotKey(Handle,hotkey,MOD_CONTROL ,VK_Space) then
showmessage('can not register the hotkey');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey(handle, HotKey);
end;
end.
上面没有什么解释,真是抱歉,但如果看了上面的文字,我想也不难看得懂吧。把你的光标放在任何一个窗口上,按Ctrl+Space,看是不是把这个窗口抓下来了呢如果你将光标指在一个窗口内部的控件上,再按Ctrl+Space,这时候抓到的就是这个控件了。是不是很有意思呢。
其实,有了句柄,真的是好办,可以做好多的事情。