简体   繁体   中英

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.

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.

So, is there any sort of API (I'd imagine I would have to P/Invoke into it) that allows you to do this? 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.

How to get the handles of child controls is then another story but Win32 has all you need for it.

Send the WM_GETTEXT message to the control once you know its handle.

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. Send this to FindWindow to get the top level window handle. Finally call EnumChildWindows to walk the children. Spy++ can also tell you how to identify which child is of interest.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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