有没有办法让MSAA IAccessible遍历更快?

时间:2012-06-19 14:47:11

标签: c++ winapi accessibility msdn

现在我有了这个C ++函数(删除了安全检查和一些代码以使其更具可读性):

HRESULT WalkTreeWithAccessibleChildren(wstringstream *ss, IAccessible* pAcc, int depth)
{
    long childCount;
    long returnCount;   

    VARIANT* pArray = new VARIANT[childCount];
    hr = AccessibleChildren(pAcc, 0L, childCount, pArray, &returnCount);
    for (int x = 0; x < returnCount; x++) {
        VARIANT vtChild = pArray[x];
        Get the role and name of the component here
        // If it's an accessible object, get the IAccessible, and recurse.
        if (vtChild.vt == VT_DISPATCH) {
            IDispatch* pDisp = vtChild.pdispVal;
            IAccessible* pChild = NULL;
            hr = pDisp->QueryInterface(IID_IAccessible, (void**) &pChild);
            WalkTreeWithAccessibleChildren(ss, pChild, depth + 1);
    }
}

对于组件相对较少(200左右)的某些程序,例如Paint.NET,这需要大约2整秒,有没有办法让这个功能更快,在一个COM调用中得到所有组件或类似的东西?

1 个答案:

答案 0 :(得分:3)

这在某种程度上取决于你想要做什么。

如果您正在寻找特定商品,您有时可以使用导航(accNavigate)更快地获取商品,而不是查看所有商品。

如果你真的需要获得所有项目,背景线程效果很好。

另一种选择是使用UIAutomation api它仍支持所有IAccessible服务器,并且它内置了更丰富的缓存和过滤功能。在MSDN上查找IUIAutomationCacheRequest,它的方法是TreeFilter和TreeScope以获取更多信息。如果您处于特定项目案例中,它还可以搜索特定项目。

将UIAutomation视为IAccessible的超集。 UIAutomation可在Vista SP2及更高版本上使用。

相关问题