为什么使用treecope_children时,在桌面上设置属性ChangeDeventHandler不起作用?

发布于 2025-01-31 18:02:18 字数 1031 浏览 2 评论 0原文

我正在使用Microsoft的UIAUTomation框架在C ++工作。当桌面上的任何顶级窗户更改标题时,我需要通知我。 在我的理解中,我应该能够在桌面上注册属性ChangeDeventHandler,以观察UIA_NAMEPROPERPYID的更改。该处理程序的范围应该是TreeCope_Children,因为我不在乎窗户的较低级别。

代码应该看起来像这样:

IUIAutomationPropertyChangedEventHandler* eHandler = <create a handler>;
IUIAutomationElement* deskTopElement = <retrieve the desktop element>;
CComSafeArray<PROPERTYID> propArray(1);
propArray[0] = UIA_NamePropertyId;

uiaInterface->AddPropertyChangedEventHandler(deskTopElement, TreeScope_Children, NULL, eHandler, propArray);

我得到了s_ok的hresult,事情看起来还不错。但是,我从来没有任何活动。

如果我将范围更改为TreeCope_descendants,那么我就会开始获取所有所需的事件,即顶级窗口标题的更改,以及所有低级窗口的事件。对我来说,这意味着我要正确设置事件处理程序,它只是无法正确处理treecope_children范围。

我对此感到困惑,因为如果我使用accevent.exe来寻找这些事件,它可以按照我的期望来奏效:我选择桌面作为实体,而“直接的孩子”可以包括事件。我选择了Property Id的名称,然后让它去镇上。我得到了我期望的所有事件,而我不想要的一切。

那么,有人对我做错什么有任何想法吗?

请注意,我可以通过收集桌面的所有直接孩子,然后在每个台面上设置一个类似的处理程序,然后使用Scope TreeCope_Element,然后观看新的窗户并在每个新窗口上设置一个处理程序。但是对于这样的(看似)简单的任务来说,这似乎太过分了。

I'm working in C++ using Microsoft's UIAutomation framework. I have a need to be notified when any top-level windows on the desktop have their title changed.
In my understanding, I should just be able to register a PropertyChangedEventHandler on the desktop to watch for UIA_NamePropertyID changes. The scope of that handler should be TreeScope_Children, because I don't care about the lower levels of the windows.

The code should look like this:

IUIAutomationPropertyChangedEventHandler* eHandler = <create a handler>;
IUIAutomationElement* deskTopElement = <retrieve the desktop element>;
CComSafeArray<PROPERTYID> propArray(1);
propArray[0] = UIA_NamePropertyId;

uiaInterface->AddPropertyChangedEventHandler(deskTopElement, TreeScope_Children, NULL, eHandler, propArray);

I get an HRESULT of S_OK, and things look all right. However, I never get any events.

If I change the scope to TreeScope_Descendants, then I start getting all the desired events, those of the top-level window title changes, but also ALL the lower-level ones. This means, to me, that I'm setting the event handler up correctly, it's just unable to process the TreeScope_Children scope correctly.

I'm rather confused about this, because if I use AccEvent.exe to look for those events, it works as I expect: I select Desktop as the entity, and "Immediate children" from which to include events. I select the Name PropertyID and let it go to town. I get all the events I expect, and none of what I don't want.

So, does anyone have any ideas as to what I'm doing wrong?

Note that I can work around this by gathering all the immediate children of the desktop, then setting a similar handler on each of them with scope TreeScope_Element, then watching for new windows and setting a handler on each new one. But that seems rather overkill for such a (seemingly) simple task.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文