It seems mistake on following lines.
hh = Type.GetTypeHandle(hwnd);
t = Type.GetTypeFromHandle(hh);
(The convert to type isn't good).
If I inspect hwnd on "watch window", I see that it has one static property
"size", with value 4 (That's seems the structure of IntPtr).
In other words: just need to find the control, by having its handle only ...
Thanks
"Mr. X." wrote in message
As my previous post (see the following code on C# again), I overcome the
problem of converting IntPtr to RuntimeTypeHandle (it's RuntimeTypeHandle.
not hwnd, and now, that I have the handle of that class - It make scenes,
because when I get its class name, by WinAPI: GetClassNameW, I get the class
name I expected).
I have the control's handle (the following code, get a hwnd as IntPtr input
parameter).
The code uses reflection, but what I have found nothing special - only one
property (maybe, by mistake, or something default : size, that has the
length of 4).
As I stated on previous post, I think a control doesn't necessarily expose
all of its properties - but when it does?
What should be necessary that I can use reflection to a specific control?
(The goal is - There is a 3rd-party class, I don't know nothing about it,
but I need to change some of it's elements).
public static bool WindowEnumProc(IntPtr hwnd, int lParam)
{
RuntimeTypeHandle hh;
Type t;
PropertyInfo[] pi;
object o;
hh = Type.GetTypeHandle(hwnd);
t = Type.GetTypeFromHandle(hh);
pi = t.GetProperties();
for (int i = 0; i < pi.Length; i++)
{
propName = pi.ElementAt(i).Name;
MessageBox.Show(propName, "property name");
p = t.GetProperty(propName);
o = p.GetValue(hwnd, null);
MessageBox.Show(text + ".." + propName + ".." + o.ToString(),
"property");
}
}
// there is only one property exposed (for my case is: Size, and always =
4).
// For my concusion for now, a control doesn't necessaraly expose all of
it's child controls or properties ...
"Marcel Müller" wrote in message
I found:
Type.GetTypeFromHandle(h)
h should be hwnd, but what if I need to convert it from IntPtr - How can
I convert IntPtr to hwnd type?
Ehm...
I think you are really confusing things. A managed class type *never*
has a window handle (hwnd) and vice versa.
Are you talking about a *window* class? If yes, then you will not be
able to use reflections. Window classes respond to window messages in a
certain way. But you cannot examine this behavior by reflection. All you
have is the class name. And either you know what it is doing or not.
There are some exceptions if you have COM windows.
Marcel