我正在Visual Studio 2022中用C++编程一个控制台应用程序,我想获取特定应用程序的“主窗体”(大的外部窗体)的IUIAutomationElement,以便以后可以获取它的子窗体。我看到两种方法:
1.使用进程ID或进程名称。我有工作源代码,可以从进程名称中获取进程ID,当然,还有进程名称(以。exe)是已知的。
1.以“查找所有应用程序”的方式,然后通过比较 * 子字符串 *(不是完整的字符串,因为这可能会有所不同!)在表单的标题中。
请注意,我 * 不想使用任何位置 *(e。例如,鼠标位置)来定位IUIAutomationElement。有人能帮帮我吗?
1条答案
按热度按时间hmae6n7t1#
在@SimonMourier和一些谷歌的帮助下,我终于解决了这个问题。首先,我需要从我的dwProcessId中获取第一个dwThreadId,我使用函数GetFirstThreadId:
然后调用EnumThreadWindows和ElementFromHandle: