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
|
type
PTreeViewEnumParam = ^TTreeViewEnumParam;
TTreeViewEnumParam = record
Nodes: TTreeNodes;
Current: TTreeNode;
end;
function EnumWindowsProc(Wnd: HWND; Param: PTreeViewEnumParam): BOOL; stdcall;
const
Cs_MaxName = 64;
Cs_MaxText = 64;
var
ParamChild: TTreeViewEnumParam;
ClassName: string;
WindowText: string;
begin
Result := True;
SetLength(ClassName, Cs_MaxName);
SetLength(ClassName, GetClassName(Wnd, PChar(ClassName), Cs_MaxName));
SetLength(WindowText, Cs_MaxText);
SetLength(WindowText, SendMessage(Wnd, WM_GETTEXT, Cs_MaxText, lParam(PChar(WindowText))));
ParamChild.Nodes := Param.Nodes;
ParamChild.Current := Param.Nodes.AddChildObject(Param.Current,
'[' + ClassName + '] "' + WindowText + '"' + ' Handle: ' + IntToStr(Wnd), Pointer(Wnd));
EnumChildWindows(Wnd, @EnumWindowsProc, lParam(@ParamChild));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Param: TTreeViewEnumParam;
begin
Param.Nodes := TreeView1.Items;
Param.Current := TreeView1.TopItem;
TreeView1.Items.BeginUpdate;
EnumWindows(@EnumWindowsProc, lParam(@Param));
TreeView1.Items.EndUpdate;
end; |
Partager