반응형
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
procedure ShowHwndAndClassName(CrPos: TPoint);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ShowHwndAndClassName(CrPos: TPoint);
var
hWnd: THandle;
aName,
Text : array [0..255] of char;
begin
hWnd := WindowFromPoint(CrPos);
Label1.Caption := 'Handle : ' + IntToStr(hWnd);
if boolean(GetClassName(hWnd, aName, 256)) then
Label2.Caption := 'ClassName : ' + string(aName)
else
Label2.Caption := 'ClassName : not found';
SendMessage(hWnd, WM_GETTEXT, SizeOf(Text), integer(@Text));
Label3.Caption := 'Text :' + Text;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.FormStyle := fsStayOnTop;
Timer1.Enabled := False;
Timer1.Interval := 50;
Timer1.Enabled := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
rPos: TPoint;
begin
if boolean(GetCursorPos(rPos)) then
ShowHwndAndClassName(rPos);
end;
end.
반응형