首页 > 解决方案 > C ++ windows ui自动化:无法列出所有子窗口

问题描述

我正在尝试特别列出所有“名称”子窗口:取消静音当前静音(按钮)

在此处输入图像描述

这是我列出所有孩子的代码:

void ListDescendants(IUIAutomationElement* pParent, int indent)
{
    if (pParent == NULL)
        return;

    IUIAutomationTreeWalker* pControlWalker = NULL;
    IUIAutomationElement* pNode = NULL;

    g_pAutomation->get_ControlViewWalker(&pControlWalker);
    if (pControlWalker == NULL)
        goto cleanup;

    pControlWalker->GetFirstChildElement(pParent, &pNode);
    if (pNode == NULL)
        goto cleanup;

    while (pNode)
    {
        BSTR desc;
        pNode->get_CurrentName(&desc);
        for (int x = 0; x <= indent; x++)
        {
            std::wcout << L"   ";
        }
        std::wcout << desc << L"\n";
        SysFreeString(desc);
      
        ListDescendants(pNode, indent+1);
        IUIAutomationElement* pNext;
        pControlWalker->GetNextSiblingElement(pNode, &pNext);
        pNode->Release();
        pNode = pNext;
    }

cleanup:
    if (pControlWalker != NULL)
        pControlWalker->Release();

    if (pNode != NULL)
        pNode->Release();

    return;
}

但输出是:

ContentLeftPanel
  VideoContainerWnd
    Video Content

我只想要那个静音/静音按钮的名称/标题..为此我需要所有子窗口的列表...

标签: c++windowswinapiui-automationmicrosoft-ui-automation

解决方案


推荐阅读