Control from HWND

M

MultiMarine

Hello

I have just started using .NET and C# from a c++ background using
win32. Now i want to do something that i used to do, without using the
win32 API.

I use Spy++ to get a HWND from another application in hex form from a
RICHEDIT control.

now i want to turn this hex value (HWND) into a control in C#.
Why doesn't this work?

IntPtr ptr = new IntPtr(0x00020A92);
Control control = System.Windows.Forms.Control.FromChildHandle(ptr);

Is there some other way to do this?? i don't wanna use the win32 API!

Thanks in advance!
 
S

Stoitcho Goutsev \(100\)

MultiMarine,

You can get a control associated with given HWND only if the control has
been created in the application from a WindowsForm class. When you create a
control the framework keeps map between HWNDs and control objects and uses
this map to when Control.FromChildHandle is called.
You cannot create a control object form a random window by its HWND.

..NET provides NativeWindow class that can be attached to any HWND and can be
used for windows subclassing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top