Search code examples
winformsautomationpinvoke

How can i retrieve a textbox control's name property from another application's window


I am writing a program that overlay's a toolbar onto another applications window. I am able to iterate through the MDI child windows and even access all the controls via PInvoke. The one thing I am trying to figure out is how to get the controls actual Name property.

I am able to see the name of the field using Hawkeye but I cannot figure out how it is getting the control name.

One thought is that it may be injecting something into the target application and running something like Control.FromHandle but I am not 100% sure.

Thanks for any help.


Solution

  • Unfortunately, the Name property of a control is a property of the .Net object that creates the window not of the control window itself. There is no way to get this value using the window handle - PInvoke or otherwise - from outside of the process.

    You would need to do some variation on what Hawkeye appears to do. Attach to the process, examine the object hierarchy and/or inject code dynamically using the CLR Debugging API.