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 使用者介面自動化 樹狀結構中的上階元素;也就是說,TreeScope_Ancestors不是範圍參數的有效值。

在桌面上搜尋最上層視窗時,請務必在 scope 參數中指定TreeScope_Children,而不是TreeScope_Descendants。 透過桌面整個子樹的搜尋可能會逐一查看數千個專案,並導致堆疊溢位。

如果您的用戶端應用程式可能會嘗試在自己的使用者介面中尋找元素,您必須在個別線程上進行所有 使用者介面自動化 呼叫。

此函式會忽略原始樹狀結構中的專案。 呼叫 FindFirstBuildCache 以在傳遞至該函式的 IUIAutomationCacheRequest 上指定適當的 TreeScope 來搜尋原始樹狀結構。

規格需求

需求
最低支援的用戶端 Windows 7、Windows Vista sp2 和 Platform Update for Windows Vista、Windows XP with SP3 和 Platform Update for Windows Vista [僅限桌面應用程式]
最低支援的伺服器 Windows Server 2008 R2、Windows Server 2008 SP2 和 Platform Update for Windows Server 2008、Windows Server 2003 SP2 和 Platform Update for Windows Server 2008 [僅限桌面應用程式]
目標平台 Windows
標頭 uiautomationclient.h (包含 UIAutomation.h)

另請參閱

概念

FindAll

FindAllBuildCache

FindFirstBuildCache

IUIAutomationElement

取得 UI 自動化項目

參考