结构事件处理程序传递“空”。 IUIAutomationElements? [英] Structure event handler delivering "empty" IUIAutomationElements?

查看:102
本文介绍了结构事件处理程序传递“空”。 IUIAutomationElements?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重新编写一个用C#编写的基于UIAutomation COM的应用程序来识别属于感兴趣的进程的窗口,这样我就可以专注于自动化,而不是占用整个桌面。我为root的子进行FindAll,获取进程ID,
将其与进程名称进行匹配,与我的命中列表进行比较,如果我得到匹配,则从那里进行进一步处理。到目前为止,这么好,效果很好。


然后我注册了一个结构更改事件处理程序,这样我就可以选择任何正在进行的窗口。它为ProcessID和RuntimeID启用了缓存。注册也顺利进行。 (所有这些都发生在MTA后台线程中。) 


然后我启动一个应用程序,并按照预期使用ChildAdded触发事件。当我检查"发件人"时在调试器中,我当前所有字段都显示E_FAIL,没有任何缓存数据存在 - ArgumentException - 和GetRuntimeId()将E_FAIL抛出为
。即使我在缓存上指定了Children,GetCachedParent()也给出了null。那里肯定有一个COM对象,但它没有给我任何爱。 :(


这个的整体结构 - 控制台应用程序[MTAThread]带有后台线程(ApartmentState.MTA),然后在实际使用的逻辑上调用Start()和Stop()自动化 - 与原始应用程序相同,出现
在这方面工作得更好。对于我的新方法,我编写了一个实现Start()和Stop()方法的新类,其中有一些不同的底层逻辑。所以我我倾向于认为问题必须是新课程的本地问题,而不是系统问题。


什么样的错误会造成这种症状?我应该寻找什么样的东西?

解决方案

我想我找到了答案,以我自己的问题的一部分。我有Scope_Children为我的两个结构的事件处理程序,并为我的缓存。当我打开我的缓存来Scope_Element同时使用Scope_Children事件处理程序,我得到了我的缓存数据为
ChildAdded。


但奇怪的是WA还会选择在devenv变量上弹出的悬停窗口。



  • 这些不应该是devenv的子窗口吗?或者他们也是根源?

所以我现在可以检测到添加了root的子项。然而,我与Scope_Children对根处理程序
不会 获得ChildRemoved通知根当应用程序主窗口关闭。 


我尝试添加第二个事件通知,这次是针对root的Scope_Element,但这只是给出了"ChildrenInvalidated"。在任何顶级窗口中添加或删除。



  • 是否无法及时通知添加或删除单个顶级窗口使用单一结构请求事件处理程序进行缓存而不使用像Scope_Subtree这样的更具包容性的处理程序?
  • 如果没有,我需要什么样的处理程序元素,处理程序范围和缓存范围的组合来解决这个问题?

谢谢......


I'm currently reworking a UIAutomation COM-based application written in C# to identify windows belonging to processes of interest so I can focus my automation rather than taking on the whole desktop. I do a FindAll for children of root, get the process ID, match it up to a process name, compare against my hit-list, and if I get a match I do further processing from there. So far, so good, works great.

Then I register a structure change event handler so I can pick up any windows coming or going. It has caching enabled for ProcessID and RuntimeID. The registration also goes off without a hitch. (All this is happening in a MTA background thread.) 

Then I start up an application and the event fires with ChildAdded, as expected. When I examine the "sender" in the debugger, all my current fields show E_FAIL, none of the cached data is present - ArgumentException - and GetRuntimeId() throws E_FAIL as well. Even though I specified Children on the caching, GetCachedParent() gives null also. There's definitely a COM object there but it isn't giving me any love. :(

The overall structure of this - console application [MTAThread] with background thread (ApartmentState.MTA) that then invokes Start() and Stop() on the logic that actually works with the automation - is the same as the original application which appeared to work much better in this respect. For my new approach I wrote a new class implementing the Start() and Stop() methods with somewhat different underlying logic. So I'm inclined to think the problem must be local to the new classes rather than systemic.

What kind of error could create this kind of symptom? What sort of thing should I be looking for?

解决方案

I think I found a part of the answer to my own question. I had Scope_Children for both my structure event handler and for my caching. When I switched my caching to Scope_Element while using Scope_Children for the event handler, I got my cached data for the ChildAdded.

Oddly, it was also picking up the hover windows that pop up on devenv variables.

  • Shouldn't those be child windows of the devenv? Or are they also drawn on root?

So I can now detect children of root being added. However, my handler with Scope_Children on Root does not get a ChildRemoved notification on the root when an application main window is closed. 

I tried adding a second event notification, this time for Scope_Element on root, but that just gives "ChildrenInvalidated" on any top-level window added or removed.

  • Is it impossible to get timely notification of addition or removal of individual top-level windows one-by-one with caching using a single structure request event handler without a more inclusive handler like Scope_Subtree?
  • If not, what combination of handler element, handler scope, and caching scope do I need to pull this off?

Thanks...


这篇关于结构事件处理程序传递“空”。 IUIAutomationElements?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆