0

我有一个 Metro 应用程序。我正在开发一个自动化客户端。我想列出 Metro 应用程序的所有元素。

  1. 我正在通过 IApplicationActivationManager 启动 Metro App
  2. 我得到了重点元素

    HRESULT hr = 自动化->GetRootElement(&pRoot);
    hr = 自动化->GetFocusedElement(&pFound);

现在我想列出所有控件,如按钮、图片元素和其他

我正在使用 FindAll 的自动化接口来获取元素,

    // Create a property condition for the button control type.   
    VARIANT varProp;  
    varProp.vt = VT_I4;  
    varProp.lVal = UIA_ButtonControlTypeId;  
    hr = automation->CreatePropertyCondition(UIA_ControlTypePropertyId, varProp, &pButtonCondition);   

    if (pButtonCondition == NULL)
        goto cleanup;

    // Create a property condition for the enabled property.
    varProp.vt = VT_BOOL;
    varProp.boolVal = VARIANT_TRUE;
    hr = automation->CreatePropertyCondition(UIA_IsEnabledPropertyId, varProp, &pEnabledCondition);
    if (pEnabledCondition == NULL)
        goto cleanup;


    // Combine the conditions.
    hr = automation->CreateAndCondition(pButtonCondition, pEnabledCondition, &pCombinedCondition);
    if (pCombinedCondition == NULL)
        goto cleanup;

    // Find the matching elements. Note that if the scope is changed to TreeScope_Descendants, 
    // system buttons on the caption bar will be found as well.
    hr = pParent->FindAll(TreeScope_Children, pCombinedCondition, &pFound);

Metro 应用程序中的此唯一列表按钮。我想列出窗口上的所有控件。
请帮助解决这个问题。如何获取 Metro 应用程序的所有元素?

4

1 回答 1

1

我找到了......如果我们使用真实条件,我们可以在 UI 上找到所有元素

IUIAutomationCondition* pCombinedCondition = NULL;
 hr = automation->CreateTrueCondition(&pCombinedCondition);
if (pCombinedCondition == NULL)
    goto cleanup;
// Find the matching elements. Note that if the scope is changed to TreeScope_Descendants, 
// system buttons on the caption bar will be found as well.
hr = pParent->FindAll(TreeScope_Children,pCombinedCondition , &pFound);
于 2012-08-07T09:25:27.440 回答