Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top