IUIAutomationElement::FindFirst 方法 (uiautomationclient.h)

检索与指定条件匹配的第一个子元素或后代元素。

语法

HRESULT FindFirst(
                TreeScope              scope,
  [in]          IUIAutomationCondition *condition,
  [out, retval] IUIAutomationElement   **found
);

参数

scope

[in] condition

类型: IUIAutomationCondition*

指向表示要匹配的条件的条件的指针。

[out, retval] found

类型: IUIAutomationElement**

接收指向 元素的指针。 如果未找到匹配的元素,则返回 NULL

返回值

类型: HRESULT

如果该方法成功,则返回 S_OK。 否则,将返回 HRESULT 错误代码。

注解

搜索范围相对于调用方法的元素。 元素按在树中遇到元素的顺序返回。

此函数无法搜索 Microsoft UI 自动化 树中的上级元素;也就是说,TreeScope_Ancestors 不是范围参数的有效值。

在桌面上搜索顶级窗口时,请确保在 scope 参数中指定TreeScope_Children,而不是TreeScope_Descendants。 在桌面的整个子树中搜索可能会循环访问数千个项目,并导致堆栈溢出。

如果客户端应用程序可能尝试在其自己的用户界面中查找元素,则必须在单独的线程上进行所有UI 自动化调用。

此函数忽略原始树中的元素。 调用 FindFirstBuildCache 以搜索原始树,方法是在传递给该函数的 IUIAutomationCacheRequest 上指定相应的 TreeScope

要求

要求
最低受支持的客户端 Windows 7、带 SP2 的 Windows Vista 和适用于 Windows Vista 的平台更新、带 SP3 的 Windows XP 和适用于 Windows Vista 的平台更新 [仅限桌面应用]
最低受支持的服务器 Windows Server 2008 R2、带 SP2 的 Windows Server 2008 和适用于 Windows Server 2008 的平台更新、带 SP2 的 Windows Server 2003 和适用于 Windows Server 2008 的平台更新 [仅限桌面应用]
目标平台 Windows
标头 uiautomationclient.h (包括 UIAutomation.h)

请参阅

概念性

FindAll

FindAllBuildCache

FindFirstBuildCache

IUIAutomationElement

获取 UI 自动化元素

引用