在Windows中,如何枚举并从另一个窗口的控件中获取文本?

时间:2021-11-09 21:08:23

More particularly - I have a window handle of another running application. This application contains a TListControl.UnicodeClass control somewhere (I know this from Winspector). How can I, using the Windows API and that window handle, go through all the items in that list control and get the text from all of the items?

更具体地说 - 我有另一个正在运行的应用程序的窗口句柄。这个应用程序在某个地方包含一个TListControl.UnicodeClass控件(我从Winspector知道这个)。我如何使用Windows API和该窗口句柄浏览该列表控件中的所有项目并从所有项目中获取文本?

You can assume the language is C/C++, though I'll actually be using win32all for python. References to the appropriate API calls would be great.

你可以假设语言是C / C ++,虽然我实际上将使用win32all for python。对适当的API调用的引用会很棒。

2 个解决方案

#1


Above answers are completely wrong and don't even know what is a PAS. This has been answered hundreds of times for 20 years on Usenet. You must use IPC of course (RPM)

以上答案是完全错误的,甚至不知道什么是PAS。在Usenet上已经有20年的回答数百次了。您当然必须使用IPC(RPM)

ask on news://comp.os.ms-windows.programmer.win32 for code.

询问新闻://comp.os.ms-windows.programmer.win32代码。

#2


You want EnumWindows and EnumChildWindows for the enumeration. See here for examples and usage info/warnings.

您需要EnumWindows和EnumChildWindows进行枚举。请参阅此处以获取示例和使用信息/警告。

For window text, once you have the appropriate HWND, you want GetWindowText in general, and control-specific API's if the text is stored in a different place (eg: list controls). For the specific control, you will need to know the specific API, and it may not be available though just Windows API calls (for example, controls with owner-draw items can store their text in the app, not accessible to Windows).

对于窗口文本,一旦有了适当的HWND,一般需要GetWindowText,如果文本存储在不同的地方(例如:列表控件),则需要特定于控件的API。对于特定控件,您需要知道特定的API,并且它可能不仅仅是Windows API调用(例如,具有所有者绘制项的控件可以将其文本存储在应用程序中,Windows无法访问)。

#1


Above answers are completely wrong and don't even know what is a PAS. This has been answered hundreds of times for 20 years on Usenet. You must use IPC of course (RPM)

以上答案是完全错误的,甚至不知道什么是PAS。在Usenet上已经有20年的回答数百次了。您当然必须使用IPC(RPM)

ask on news://comp.os.ms-windows.programmer.win32 for code.

询问新闻://comp.os.ms-windows.programmer.win32代码。

#2


You want EnumWindows and EnumChildWindows for the enumeration. See here for examples and usage info/warnings.

您需要EnumWindows和EnumChildWindows进行枚举。请参阅此处以获取示例和使用信息/警告。

For window text, once you have the appropriate HWND, you want GetWindowText in general, and control-specific API's if the text is stored in a different place (eg: list controls). For the specific control, you will need to know the specific API, and it may not be available though just Windows API calls (for example, controls with owner-draw items can store their text in the app, not accessible to Windows).

对于窗口文本,一旦有了适当的HWND,一般需要GetWindowText,如果文本存储在不同的地方(例如:列表控件),则需要特定于控件的API。对于特定控件,您需要知道特定的API,并且它可能不仅仅是Windows API调用(例如,具有所有者绘制项的控件可以将其文本存储在应用程序中,Windows无法访问)。