现在我有这个 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 调用中获取所有组件或类似的东西?