基于这个post,我正在尝试将我的代码从使用托管c# do自动化转换到使用由tlbimp.exe SDK工具生成的UIAManaged包装器(参见上面链接的帖子以了解如何做到这一点)。
我正在尝试使用UIAManaged包装器来尝试在我的应用程序中获得一些性能提升。
现在,我有一个类似如下的方法:
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。--开始下面的代码)
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帖子?
发布于 2015-10-09 22:53:02
我想我已经弄明白了。
我更改了签名以接受不同的类型(IUIAutomationElement)。一旦我有了这个新类型(就像在UIManaged包装器中定义的那样,事情很快就到位了)
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
);
}https://stackoverflow.com/questions/33038891
复制相似问题