471,072 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,072 software developers and data experts.

Control from HWND

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!

Feb 28 '06 #1
1 12064
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.
--
HTH
Stoitcho Goutsev (100)

"MultiMarine" <mu***********@hotmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
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!

Feb 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by tlviewer | last post: by
5 posts views Thread by Tom Gur | last post: by
2 posts views Thread by qhimq | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.