首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用UIA托管包装器创建缓存请求

使用UIA托管包装器创建缓存请求
EN

Stack Overflow用户
提问于 2015-10-09 20:57:32
回答 1查看 641关注 0票数 1

基于这个post,我正在尝试将我的代码从使用托管c# do自动化转换到使用由tlbimp.exe SDK工具生成的UIAManaged包装器(参见上面链接的帖子以了解如何做到这一点)。

我正在尝试使用UIAManaged包装器来尝试在我的应用程序中获得一些性能提升。

现在,我有一个类似如下的方法:

代码语言:javascript
复制
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);
                }
            }
}

我想要做的是将上面的方法转换为使用UIAManaged包装器来做同样的事情-目的是比较这两种方法,看看我是否通过转换为使用不同的dll来获得性能提升。

到目前为止,我已经找到了正确的搜索方法(例如,使用这个新的包装器执行find all。--开始下面的代码)

代码语言:javascript
复制
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?

}

有没有人做过类似的事情?有没有关于使用tlbimp.exe SDK工具生成的这个UIAManaged包装器的文章/博客文章/SO帖子?

EN

回答 1

Stack Overflow用户

发布于 2015-10-09 22:53:02

我想我已经弄明白了。

我更改了签名以接受不同的类型(IUIAutomationElement)。一旦我有了这个新类型(就像在UIManaged包装器中定义的那样,事情很快就到位了)

代码语言:javascript
复制
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
        );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33038891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档