简体   繁体   English

.NET在win32应用程序表单上的访问控制文本

[英]Access Control Text on win32 application form from .NET

In the past I've used the (P/Invoke) method GetWindowText to grab the window title text of a running application, regardless of it being Win32, .NET or otherwise. 过去,我使用(P / Invoke)方法GetWindowText来获取正在运行的应用程序的窗口标题文本,而不管它是Win32,.NET还是其他语言。

What I'm trying to figure out is if there is a way to access text on actual controls, inside a form. 我想弄清楚的是,是否有一种方法可以访问窗体内实际控件上的文本。 I realize that this would probably be difficult and I will likely be address the controls by some random hex value or something and that it could break if the software every changes at all (it's something I have no control over). 我意识到这可能很困难,并且我可能会用一些随机的十六进制值或其他方式来处理控件,并且如果软件的所有更改都可能会破坏控件(这是我无法控制的)。 But, I'm just trying to do this to add some data polling to my media center setup and would like to be able to pull some information from a media player for which there is no API. 但是,我只是想这样做,以便将一些数据轮询添加到我的媒体中心设置中,并且希望能够从没有API的媒体播放器中提取一些信息。

So, is there any sort of API (I'd imagine I would have to P/Invoke into it) that allows you to do this? 那么,是否有任何一种API(我想我必须P / Invoke到它)允许您执行此操作? Code examples would be greatly appreciated. 代码的例子,将不胜感激。

I believe GetWindowText takes the window handle as parameter, many controls ( but not all of them ) also have the window handle and you should be able to use the same API to get the text out of them. 我相信GetWindowText将窗口句柄作为参数,许多控件(但不是全部)也都具有窗口句柄,您应该能够使用相同的API从其中获取文本。

How to get the handles of child controls is then another story but Win32 has all you need for it. 那么如何获得子控件的句柄是另一个故事,但是Win32拥有您所需要的一切。

Send the WM_GETTEXT message to the control once you know its handle. 知道控件的句柄后,将WM_GETTEXT消息发送给该控件。

To work out its handle first of all use Spy++ or some such tool to find the name of the top level window and its window class name. 要首先确定其句柄,请使用Spy ++或此类工具来查找顶级窗口的名称及其窗口类名称。 Send this to FindWindow to get the top level window handle. 将其发送到FindWindow以获得顶级窗口句柄。 Finally call EnumChildWindows to walk the children. 最后调用EnumChildWindowsEnumChildWindows孩子。 Spy++ can also tell you how to identify which child is of interest. Spy ++还可以告诉您如何识别哪个孩子是您感兴趣的孩子。

Of course you may be unlucky and find that the control of interest is implemented without its own window handle, but Spy++ will tell you that too. 当然,您可能很不幸,会发现感兴趣的控件是在没有自己的窗口句柄的情况下实现的,但是Spy ++也会告诉您。

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

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