简体   繁体   English

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

[英]In Windows, how can I enumerate and get text from another window's controls?

More particularly - I have a window handle of another running application. 更具体地说-我有另一个正在运行的应用程序的窗口句柄。 This application contains a TListControl.UnicodeClass control somewhere (I know this from Winspector). 该应用程序在某处(我从Winspector知道)包含一个TListControl.UnicodeClass控件。 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? 如何使用Windows API和该窗口句柄浏览该列表控件中的所有项目,并从所有项目中获取文本?

You can assume the language is C/C++, though I'll actually be using win32all for python. 您可以假设该语言是C / C ++,尽管我实际上将win32all用于python。 References to the appropriate API calls would be great. 引用适当的API调用会很棒。

You want EnumWindows and EnumChildWindows for the enumeration. 您需要EnumWindows和EnumChildWindows进行枚举。 See here for examples and usage info/warnings. 有关示例和用法信息/警告,请参见此处

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). 对于窗口文本,一旦拥有适当的HWND,则通常需要GetWindowText ,如果文本存储在其他位置(例如:列表控件),则需要特定于控件的API。 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). 对于特定的控件,您将需要了解特定的API,并且可能仅通过Windows API调用就无法使用该API(例如,具有所有者绘图项的控件可以将其文本存储在应用中,Windows无法访问)。

Above answers are completely wrong and don't even know what is a PAS. 以上答案是完全错误的,甚至不知道什么是PAS。 This has been answered hundreds of times for 20 years on Usenet. 在Usenet上,这已经有20年的历史了数百次。 You must use IPC of course (RPM) 当然,您必须使用IPC(RPM)

ask on news://comp.os.ms-windows.programmer.win32 for code. 询问news://comp.os.ms-windows.programmer.win32以获取代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM