1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
HEdit: TEdit;
ClassEdit: TEdit;
TextEdit: TEdit;
IdxEdit: TEdit;
Label4: TLabel;
UPEdit: TEdit;
Label5: TLabel;
UPCEdit: TEdit;
Label6: TLabel;
Panel2: TPanel;
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TFResult=record
H:HWND;
Idx,Ps:integer;
end;
PFResult =^TFResult;
var
Pv:HWND;
procedure FocusRect(Hd:HWND);
var
R:TRect;
DC:HDC;
begin
DC := GetWindowDC(Hd);
GetClipBox(DC,R);
InflateRect(R,-1,-1);
DrawFocusRect(DC,R);
ReleaseDc(Hd,DC);
end;
function WinClassName(Hd:HWND):string;
begin
SetLength(result,255);
SetLength(result,GetClassName(Hd,PChar(result),255));
end;
function WinTxt(Hd:HWND):string;
begin
SetLength(result,255);
SetLength(result,GetWindowText(Hd,PChar(result),255));
end;
function GetFirstParent(Control: HWND): HWND;
begin
result:= Control;
repeat
Control:=GetParent(Control);
if Control = 0 then
Exit;
result:= Control;
until False;
end;
function ChildIdx(HParent,HChild:HWND):integer;
function EnumChildProc(Hd:HWND;Param:PFResult):BOOL;stdcall;
begin
inc(Param^.Ps);
if Param^.H = Hd then
Param^.idx := Param^.Ps;
result:= Param^.idx = -1;
end;
var
Sr:TFResult;
begin
Sr.Idx :=-1;
Sr.Ps:=-1;
Sr.H :=HChild;
EnumChildWindows(HParent,@EnumChildProc,DWORD(@Sr));
result:=Sr.Ps
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
H,PC,CH:HWND;
M:TPoint;
begin
if not (ssLeft in Shift) then Exit;
if PtinRect(ClientRect,Point(X,Y)) then Exit;
M:=Mouse.CursorPos;
CH:= WindowFromPoint(Mouse.CursorPos);
Windows.ScreentoClient(CH,M);
H:= ChildWindowFromPointEx(CH,M,CWP_ALL);
if H =0 then
H:=CH;
if Pv <> H then
begin
FocusRect(Pv);
FocusRect(H);
PC :=GetFirstParent(CH);
HEdit.Text := '$'+IntToHex(H,8);
ClassEdit.Text:=WinClassName(H);
TextEdit.Text:=WinTxt(H);
IdxEdit.Text:=IntToStr(ChildIdx(PC,H));
UPEdit.Text:='$'+IntToHex(PC,8);;
UPCEdit.Text:=WinClassName(PC);
Pv := H;
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FocusRect(Pv);
end;
end. |
Partager