From: Willy Denoyette [MVP] on
Don't mix the two worlds: Windows Forms (managed code) and Win32 API (native
code), what you see in VS and called properties, are a consolidation of
class attributes, window attributes and properties. When calling into Win32
through PInvoke, as you have to do to obtain the Windows attributes of a
external Windows Application from a Windows Forms application, you are
transitioning between managed and unmanaged code, this involves a lot of
PInvoke declarations because you are calling into an API designed for C++
not for .NET.
Now, when you want to obtain individual attributes of an external window,
you have to invoke the Win32 API's, like GetClassName, GetWindowText,
GetParent etc...
If you need a lot of attributes (like SPYxx is doing), you better call
GetWindowInfo because this one returns a lot of attributes in a structure.
Same if you need the Window styles (returned in a WINDOWINFO struct) you
need to inspect the individual Style attribute returned like BUTTON, BUTT
..., the same goes for the extended styles.
If you need the properties and extended properties, you need to call
EnumPropsEx etc..

You see, this all involves a lot of work, and is not something done by
regular user application but is the domain of tools like property editors,
SPYxx and others. The fact that the API's are C style API, most of the
samples found on the internet are C++, if you google around you will find a
number of sample, it's only a matter of porting them to C# and you are done,
but when you don't have a good grasp of .NET Interop AND native Windows
hierarchies, attributes and styles it's quite involving. But no-one ever
said that programming was easy, right?

Willy.





I told you that it's not easy to do this from C#
"SQACSharp" <lsdisciples(a)hotmail.com> wrote in message
news:1163018679.409745.291420(a)i42g2000cwa.googlegroups.com...
What is the meaning of managed vs unmanaged???

Since it takes me almost a day of work just to understand how to work
with GetProps, atom name, etc. maybe you can point me to the right
function?

I try to use EnumProps ,i'm still having a problem for displaying the
properties of an object (a window hwnd) but i can that this function is
not exactly what I need because when callng the enumprops function i
can see that the enumpropPROC is called only 4-5 times....Since I have
almost 20-30 properties for my object it look like enumprops cannot
retreive them.

Just to make sure you understand what im trying to do : in C# create a
new project, go in design mode, add a new TextBox and select
"properties window" in the view menu. All the properties displayed in
this window are the properties I need to retreive from the textBox.
The particular thing in my case is that this textbox is not in my form
but it's in an external application/window

Is it me or theses functions are REALLY REALLY hard to use and
understand??? Is there any good place with code example about theses
functions instead of loosing all the days trying to use it in my code?

Thanks,


Willy Denoyette [MVP] a ?crit :

> "SQACSharp" <lsdisciples(a)hotmail.com> wrote in message
> news:1162992988.673013.261950(a)e3g2000cwe.googlegroups.com...
> | Thanks again willy, now i can browse all the object in my window!
> |
> | The only thing i'm still playing with is to be able to retreive the
> | properties of an object with it's handle. I try GetProps, GetProp API
> | is it the correct API function to do this?
> |
> | Michel
> |
>
> You have the choice, depending on what you want:
> GetWindowsRect, GetClassName, GetWindowsText, GetWindowsInfo, GetProp,
> EnumProps and EnumPropsEx.
> EnumProp and EnumPropsEx are the ones you should start with, but beware
> there is a lot of marshaling to do between unmanaged and managed.
> Willy.