我使用Windows UI Automation框架来访问其他进程中的控件。我捕获系统SETFOCUS消息并检查聚焦控件的类型(如果它是编辑控件)。这有时可以很好地工作,但有时我不会从setfocus消息获得聚焦控制,而只能获得树中上部控件的句柄,例如窗格的句柄。我究竟做错了什么? 我试图通过检查启用的子元素的UIA_HasKeyboardFocusPropertyId来找出窗格的哪个子元素当前获得键盘焦点,但是所有这些元素都将返回false。 下面是检查键盘焦点属性的代码。 此外,由于某种原因,我无法使用自动化元素属性标识符。它们应列在此处:https://msdn.microsoft.com/en-us/library/windows/desktop/ee684017(v=vs.85).aspx 我从archive.org获得了值,因为内容不再可用。 在代码中,“i”是当前聚焦控件的类型,它获取了windows setfocus消息。
if (i = 50033) then // 50033 (pane)
begin
uiAuto.CreatePropertyCondition(30010, true, cond); // 30010 (enabled property)
if cond <> nil then
begin
focusedElement.FindAll(TreeScope_Children, cond, children);
if children <> nil then
begin
children.Get_Length(length);
if length > 0 then
begin
Memo1.Lines.Add('length: ' + IntToStr(length));
for j := 0 to length-1 do
begin
children.GetElement(j, tempChildElement);
tempChildElement.Get_CurrentControlType(k);
Memo1.Lines.Add('child element type: ' + IntToStr(k));
tempChildElement.GetCurrentPropertyValue(30008, keybFocusBool); // 30008 (UIA_HasKeyboardFocusPropertyId)
if keybFocusBool then
Memo1.Lines.Add('child has keyboard focus: TRUE');
keybFocusbool := false;
end;
end;
end;
end;
end;