Is there a way to speed up the transition of the MSAA IAccessible?

Now I have this C ++ function (removed security checks and some code to make it more readable):

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 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); } } 

For some programs with a relatively small number of components (200 or so), for example. Paint.NET, it takes about 2 full seconds, is there a way to make this function faster, get all the components in one COM call, or something like that?

+4
source share
1 answer

It depends on what you are trying to do.

If you are looking for a specific item, you can sometimes use the navigation (accNavigate) to get to the item faster, rather than viewing all the items.

If you really need to get all the items, the background thread works well.

Another option is to use the UIAutomation api, it still supports all IAccessible servers, and it has richer caching and filtering built into it. Take a look at the MSDN for IUIAutomationCacheRequest, and it uses the TreeFilter and TreeScope methods for more information. It also has a way to search for specific items if you are in a particular case.

Think of UIAutomation as an IAccessible extension. UIAutomation is available on Vista SP2 and higher.

+3
source

All Articles