views:

49

answers:

1

I need to see the component type, meaning the name of the class that was programmed, of a clicked control in another process. I need the type so I can react to the clicked control and then do some Automation tasks. Right now I am doing the following: 1. I FindWindow() from Win32 to find the main window handle of the process. 2. Then, I get call EnumChildWindows(), also from Win32, and get the window handles of all the children of the main window handle. 3. Now it gets tricky. When I call GetClassName(), it returns WindowsForms10.STATIC.app [...] since the controls I am trying to read are custom.

How can I get the type of the clicked control using the window handles from EnumChildWindows() ? Is what I am trying to do even possible? I have been looking into using SendMessage() from Win32 to the process but it seems that there is no system defined message that could help.

+1  A: 

I'm afraid that it's not possible. A handle just refers to internal data of the window that Windows needs. There is no information beyond that available.

You can get the class name, but it is neither standardized nor unique. Most controls that are not basic-functionality controls like buttons, lists, etc. are derived from a very primitive one, namely "Static". But again, there's no information about the high-level WinForms control available.

This leads to the fact that, even if you knew the type, you cannot just cast the pointer/handle, because there no data behind it.

Can you somehow restate your problem? Maybe use Remote Procedure Calls? Does it work without the high-level WinForms objects? Things like clicking, moving or renaming work with plain Win32 API.

Thank you so much for your fast answer. I've been reading a lot in the Win32 APIs with no luck. :( I need to see the top level class so I can predict what the user is trying to do. I don't need to further interact with the control. I have programmed a Hook to read the position of the mouse in the application. What I then need to do is read which component type was clicked. Casting to AutomationElement hasn't helped either, since the properties are not set properly. I saw that the ManagedSpyLib can read the component type, but it has not been compiled for .NET 4.0 so I need program it myself.
prettyCode
If you find an answer useful, you can click on the up-arrow. If it answers your question, please click on the green checkmark just under the arrows.