取得了鼠标所指控件与其父窗体的信息。
源程序代码:
-------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
p rivate
{ Private declarations }
procedure hotKeyOn;
procedure hotKeyOff;
procedure hotKeyDown(var msg:TMessage);message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{$APPTYPE CONSOLE}
var
hotKeyID:integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Lines.Clear;
hotKeyOn;
end;
procedure TForm1.hotKeyDown(var msg: TMessage);
var
pt:TPoint;
hwnd:THandle;
hwndParent:THandle;
str:array[0..255] of char;
begin
if (msg.LParamHi=VK_DELETE) and (msg.LParamLo=MOD_CONTROL) then
begin
GetCursorPos(pt);
hwnd:=WindowFromPoint(pt);
//Writeln('ok');
memo1.Lines.Add('坐标窗体句柄:'+IntToStr(hwnd));
GetWindowText(hwnd,str,256);
memo1.Lines.Add('坐标窗体标题:'+str);
GetClassName(hwnd,str,256);
memo1.Lines.add('坐标窗体类名'+str);
hwndParent:=GetParent(hwnd);
memo1.Lines.Add('父窗口句柄'+IntToStr(hwndParent));
GetWindowText(hwndParent,str,256);
memo1.Lines.Add('父窗口标题:'+str);
GetClassName(hwndParent,str,256);
memo1.Lines.Add('父窗口类名'+str);
memo1.Lines.Add(#13);
end;
end;
procedure TForm1.hotKeyOff;
begin
UnregisterHotKey(self.Handle,hotKeyID);
end;
procedure TForm1.hotKeyOn;
var
r1:BOOL;
begin
r1:=RegisterHotKey(self.Handle,
hotKeyID,MOD_CONTROL,VK_DELETE
);
if not r1 then ShowMessage('RegisterHotKey error!');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
hotKeyOff;
end;
end.
|