function EnumWindowsProc1(Wnd: HWND; LB:TListBox): BOOL;
stdcall;
const
MyMaxName = 255;
MyMaxText = 255;
var
ClassName:
String;
WindowText:
String;
begin
Result := True;
SetLength(ClassName, MyMaxName);
SetLength(ClassName,GetClassName(Wnd, PChar(ClassName), MyMaxName));
SetLength(WindowText, MyMaxText);
SetLength(WindowText,GetWindowText(Wnd,PChar(WindowText),MyMaxText));
LB.Items.AddObject('
[' + ClassName + '
] "' + WindowText + '
"' + '
Handle: ' + IntToStr(Wnd), Pointer(Wnd));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Treeview1.Items.Clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Treeview1.Items.Clear;
Listbox1.Items.Clear;
Listbox1.Items.BeginUpdate;
EnumWindows(@EnumWindowsProc1, Integer(TObject(ListBox1)));
Listbox1.Items.EndUpdate;
Listbox1.Sorted := true;
end;