type
PWindows = ^TWindows;
TWindows =
record
WindowHandle: HWND;
WindowText:
string;
end;
TForm1 =
class(TForm)
TreeView1: TTreeView;
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
PNode, CNode: TTreeNode;
AWindows: PWindows;
implementation
{$R *.dfm}
function EnumChildWindowsProc(Wnd: HWnd; Form: TForm1): Bool;
export;
{$ifdef Win32} stdcall;
{$endif}
var
Buffer:
array[0..99]
of Char;
begin
GetWindowText(Wnd, Buffer, 100);
//if StrLen(Buffer) 0 then
if StrPas(Buffer) = '
'
then Buffer := '
Empty';
new(AWindows);
with AWindows^
do
begin
WindowHandle := Wnd;
WindowText := StrPas(Buffer);
end;
CNode := Form1.TreeView1.Items.AddChildObject(PNode,
AWindows^.WindowText + '
:' +
IntToHex(AWindows^.WindowHandle, 8), AWindows);
if GetWindow(Wnd, GW_CHILD) = 0
then
begin
PNode := CNode;
Enumchildwindows(Wnd, @EnumChildWindowsProc, 0);
end;
Result := True;
end;
function EnumWindowsProc(Wnd: HWnd; Form: TForm1): Bool;
export;
{$ifdef Win32} stdcall;
{$endif}
var
Buffer:
array[0..99]
of Char;
begin
GetWindowText(Wnd, Buffer, 100);
//if StrLen(Buffer) 0 then
if StrPas(Buffer) = '
'
then Buffer := '
Empty';
new(AWindows);
with AWindows^
do
begin
WindowHandle := Wnd;
WindowText := StrPas(Buffer);
end;
PNode := Form1.TreeView1.Items.AddObject(
nil, AWindows^.WindowText + '
:' +
IntToHex(AWindows^.WindowHandle, 8), AWindows);
EnumChildWindows(Wnd, @EnumChildWindowsProc, 0);
Result := True;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc, Longint(Self));
end;