【发布时间】:2013-09-19 10:28:51
【问题描述】:
我正在用 Delphi XE2 开发一个应用程序,它通过 EnumWindows 和 EnumChildWindows 函数检查同样用 Delphi 编写的正在运行的应用程序的窗口。
这是主要代码(改编自示例:http://www.swissdelphicenter.ch/torry/showcode.php?id=410)
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 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 StrPas(Buffer) = '' then Buffer := 'Empty';
new(AWindows);
with AWindows^ do
begin
WindowHandle := Wnd;
WindowText := StrPas(Buffer);
end;
if Pos(Form1.edAppToFind.Text,AWindows^.WindowText) > 0 then // <- inspect child only for my Application
begin
PNode := Form1.TreeView1.Items.AddObject(nil, AWindows^.WindowText + ':' +
IntToHex(AWindows^.WindowHandle, 8), AWindows);
EnumChildWindows(Wnd, @EnumChildWindowsProc, 0);
end;
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc, self.Handle);
end;
一切正常,除了对象 TGroupBox 之后递归停止。但控件 TGroupBox 内部包含其他元素(TLabel)。
事实上,即使在 Delphi 中编写一个简单的应用程序,通过在 Form 中包含一个 TGroupBox,然后在 TGroupBox 中包含一个 TLabel,启动应用程序并使用 Spy++(或使用 Autoit AU3Info 工具)检查它,您也无法进入TGroupBox:里面的TLabel没有被检查。
有没有办法在 TGroupBox 中找到 TLabel 控件?
【问题讨论】:
-
TLabel不是窗口。
标签: delphi delphi-xe2 spy++ tlabel tcombobox