1

Based on this post, I am trying to convert my code from using the managed c# uiautomation over to using the UIAManaged wrapper generated by the tlbimp.exe SDK tool (see post linked above for information how to do that.

I'm trying to use the UIAManaged wrapper to try and get some performance gains in my application.

Right now, I have a method that looks something like this:

public void CacheAndPrintNames(AutomationElement element)
{
            var request = new CacheRequest
            {
                AutomationElementMode = AutomationElementMode.None,
                TreeFilter = Automation.RawViewCondition,
                TreeScope = TreeScope.Subtree
            };

            request.Add(AutomationElement.NameProperty);
            AutomationElementCollection children = null;

            using (request.Activate())
            {

                children = element.FindAll(
                    TreeScope.Descendants,
                    new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)
                );
            }

            foreach (AutomationElement child in children)
            {
                if (child != element && !String.IsNullOrWhiteSpace(child.Cached.Name))
                {
                    log(child.Current.Name);
                }
            }
}

What I would like to do is convert the method above to use the UIAManaged wrapper to do the same thing - the goal being compare the two methods and see if I get performance gains by converting to using the different dll.

I've gotten so far, but I can't find the correct way to search (i.e. execute the find all using this new wrapper. -- starting code below)

using Interop.UIAutomationCore;

        public void CacheAndPrintNames(AutomationElement element)
        {

            var uiAutomation = new CUIAutomation();

            var request = uiAutomation.CreateCacheRequest();
            request.AutomationElementMode = Interop.UIAutomationCore.AutomationElementMode.AutomationElementMode_None;
            request.AddProperty(30005); // 30005 is nameProperty

            // how do i start the cache request, and execute a FindAll search?

}

Has anyone done something similar? Are there articles/blogposts/SO posts about using this UIAManaged wrapper generated by the tlbimp.exe SDK tool?

Community
  • 1
  • 1
Jeff
  • 1,800
  • 8
  • 30
  • 54

1 Answers1

0

I think I figured this one out.

I had the change the signature to accept a different type (IUIAutomationElement). Once I had that new type (as defined in that UIManaged wrapper, things fell into place pretty quickly)

public void CacheElement(IUIAutomationElement element)
{
    var automation = new CUIAutomation();

    var request = automation.CreateCacheRequest();
    request.AutomationElementMode = AutomationElementMode.AutomationElementMode_None;
    request.AddProperty(30005); // 30005 is nameProperty

    var results = element.FindAllBuildCache(
            TreeScope.TreeScope_Descendants,
            automation.CreatePropertyCondition(30003, 50020), // 30003 is control type property 50020 is TEXT control type
            request
        );
}
Jeff
  • 1,800
  • 8
  • 30
  • 54