How do I retrieve the Control Type Name?

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I am writing an application (in C++) to interrogate the controls on any
currently running .NET application. Most of the information I need I can
retrieve from the window and class information available through the HWNDs
retrieved using the EnumChildWindows() API.

My problem occurs with controls that have the class name like
'WindowsForms10.BUTTON.app3'. So far I have seen this class name used for
button, checkbox, radio button and group box controls, and basically all the
other windows' styles are the same for each control type. The only way to
distinguish these controls is by the control type name, and as far as I can
see this property cannot be accessed from an external process.

However I have noticed that at runtime controls within a .NET application
seem to have a property/variable called 'WM_GETCONTROLNAME' which appears to
me to be a type of windows message. Sending this value as a windows message
to a .NET control has no effect.

Could someone please tell me if this WM_GETCONTROLNAME can provide me with
the functionality I need or do I need to inject my own code into the running
process in order to retrieve the information I need from the inside???

Thanks in advance...

Mike
 
Mike,
So far I have seen this class name used for
button, checkbox, radio button and group box controls

That's because they are all the same underlying Win32 user control
(BUTTON).

and basically all the
other windows' styles are the same for each control type. The only way to
distinguish these controls is by the control type name

Really? I would expect that you could distinguish them by looking for
the BS_CHECKBOX, BS_PUSHBUTTON, BS_RADIOBUTTON or BS_GROUPBOX window
styles.

However I have noticed that at runtime controls within a .NET application
seem to have a property/variable called 'WM_GETCONTROLNAME' which appears to
me to be a type of windows message. Sending this value as a windows message
to a .NET control has no effect.

Since this is a custom message Windows doesn't know how to marshal the
args cross process boundaries. So basicly the message can only be sent
in proc.



Mattias
 
Thanks for all this. However...

....the windows styles for all 4 of these control types are basically
identical (but for the last bit). None of them have the standard styles
you'd expect so that's the reason I can't test for them. (If you don't
believe me then just run Spy++ over a .NET application.)

Just to add a little more complexity to it...the group box control does not
even have a button classname (like WindowsForms10.BUTTON.app3) but rather
has one similar to a standard dialog window: WindowsForms10.Window.8.app3.
And no it doesn't have the BS_GROUPBOX style... :-(

WM_GETCONTROLNAME: That explains that then. Thanks for telling me about
this....there's no documentation on this anywhere.

Mike
 
The reason that they have the same styles is because they're drawn
by the framework itself. If you set FlatStyle to system (default is
standard)
they're drawn by the system though (and have the correct styles set)

/claes
 
Mike,
...the windows styles for all 4 of these control types are basically
identical (but for the last bit). None of them have the standard styles
you'd expect so that's the reason I can't test for them. (If you don't
believe me then just run Spy++ over a .NET application.)

As Claes said you probably have to switch to FlatStyle.System to
really see a difference.

However, Spy++ will still not display display the BS_* flags, since it
only does that for plain button controls, not derived classes like the
ones Winforms registers. (They should update that tool to use the
RealGetWindowClass API).



Mattias
 
Thanks for your continuing help guys....

Especially for the mention (if in passing) of the RealGetWindowClass API - I
had never heard of it before.
Unfortunate for me it doesn't help all that much as the styles are still
indistinguishable. Changing the Flatstyle to 'System' did have some effect
but the differences are not helpful. The extra style information is still
not recognisable as a BS_* style.

Far more important though is the fact that the tool I am writing is designed
to be used it interrogate 3rd-party software, where I have no control over
the value of the FlatStyle property. I cannot rely on other developers
having set this property to 'System' when in fact there may well be very
good reasons for them not doing so.

I guess it's back to the original idea of injecting code to retrieve the
Control Type Name...

Mike
 
Back
Top