Get component type of custom .NET class from window handle

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.


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.

链接地址: http://www.djcxy.com/p/38840.html

上一篇: 如何在C#中获得Process'主窗口句柄?

下一篇: 从窗口句柄获取自定义.NET类的组件类型