IUIAutomationElement::FindFirst 方法 (uiautomationclient.h)

擷取符合指定條件的第一個子專案或子代專案。

語法

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

參數

[in] scope

類型:TreeScope

值的組合,指定搜尋的範圍。

[in] condition

類型:IUIAutomationCondition*

表示要比對之準則之條件的指標。

[out, retval] found

類型:IUIAutomationElement**

接收專案的指標。 如果找不到相符的專案,則會傳回 NULL

傳回值

類型:HRESULT

如果此方法成功,則會傳回 S_OK。 否則,它會傳回 HRESULT 錯誤碼。

言論

搜尋的範圍相對於呼叫 方法的專案。 元素會以樹狀結構中遇到的順序傳回。

此函式無法搜尋 Microsoft UI 自動化樹狀目錄中的上階元素;也就是說,TreeScope_Ancestors 不是 範圍 參數的有效值。

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

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

此函式會忽略原始樹狀結構中的專案。 呼叫 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 [僅限傳統型應用程式]
目標平臺 窗戶
標頭 uiautomationclient.h (include UIAutomation.h)

另請參閱

概念

FindAll

FindAllBuildCache

FindFirstBuildCache

IUIAutomationElement

取得使用者介面自動化元素

參考