views:

71

answers:

1

I am using active accessibility framework to enumerate all the controls for a given program. Problem is that when I traverse the tree of controls, it takes forever on complex applications like explorer or visual studio. Simple applications take about a second but large ones with lots of controls can take 10 seconds. Anyone experience this? I also found some references to using MSAA in process versus out of process. What does this mean?

+2  A: 

First of all, be careful when traversing recursively, because it sometimes happen that there are "cycles" in the "tree", and you cannot really compare objects reliably to see whether you have already been at this object...

The main reason why Active Accessibility is so slow, is that it is just not thought to be traversed recursively, but merely to show details about one single element (below cursor) or maybe its children. Every AA request (for every property) will have to switch context to the target application and back again. And, if you are doing the AA correctly (with lots of descriptions attached to all of your UI objects), there are simply a few thousand objects which will take time to traverse...

If you are looking for something specific, it might be easier to request that directly, instead of traversing all the controls. Or if you are only looking for some kinds of objects that only appear for HWNDs with other properties you know, it is a lot faster to first enumerate all the HWNDs and then call AccessibleObjectFromWindow on them (which does not only work for toplevel windows, but also for child windows). When enumerating their children, you can stop as soon as the HWND property changes.

And add some hard max counter for the recursion depth to avoid running into one of those cycles.

mihi