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:
| type PWindows = ^TWindows; TWindows = record WindowHandle: HWND; WindowText: string; end;
type PMyEnumParam = ^TMyEnumParam; TMyEnumParam = record Nodes: TTreeNodes; Current: TTreeNode; end;
function EnumWindowsProc(Wnd: HWND; Param: PMyEnumParam): BOOL; stdcall; const MyMaxName = 64; MyMaxText = 64; var ParamChild: TMyEnumParam; ClassName: string; WindowText: string; begin Result := True; SetLength(ClassName, MyMaxName); SetLength(ClassName, GetClassName(Wnd, PChar(ClassName), MyMaxName)); SetLength(WindowText, MyMaxText); SetLength(WindowText, SendMessage(Wnd, WM_GETTEXT, MyMaxText, 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: TMyEnumParam; begin Param.Nodes := TreeView1.Items; Param.Current := TreeView1.TopItem; TreeView1.Items.BeginUpdate; EnumWindows(@EnumWindowsProc, lParam(@Param)); TreeView1.Items.EndUpdate; end; |