[quoted text, click to view] Xin Huang wrote:
> If you ildasm Control.FromHandle, you can find it is based on
> NativeWindow.FromHandle. They share the same handle map, so releasing the
> handle from NativeWindow does affect Control.FromHandle.
>
> Regards,
> Xin
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
> You assume all risk for your use. (c) 2003 Microsoft Corporation. All
> rights reserved.
>
Xin Huang wrote:
> If you ildasm Control.FromHandle, you can find it is based on
> NativeWindow.FromHandle. They share the same handle map, so releasing
the
> handle from NativeWindow does affect Control.FromHandle.
>
> Regards,
> Xin
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> You assume all risk for your use. (c) 2003 Microsoft Corporation. All
> rights reserved.
>
Well, maybe there is some misunderstanding here, I call the native Win32
API GetFocusWindow (or something similar) by PInvoke to retrieve the
(native) handle of the window. Now, just in order to get the information
on whether it is a managed control or not, I'm calling
Control.FromHandle. This returns null, if there is no managed control
for that handle (meaning it must then be something native).
What I do then is to create a new instance of the class NativeWindow and
call AssignHandle(native window handle). Then, after a while call
ReleaseHandle(). This causes the effect I mentioned.
Now, from what I know about native window handling and subclassing,
superclassing etc. this behaviour is simply wrong. As far as I'm
concerned, I just injected another layer into the window procedure.
And if I remove it (via ReleaseHandle), it should simply restore the
previous one. (This is the reason, why there is also a DestroyHandle
method?).
Anyway, I looked into the IL Code myself, and for what I see (or
interpret the code for), is that it simply replaces the native window in
the list with my new one, and I now have a child that is the original
native window. So calling base.WndProc simply forwards the message to
the previous native window. However, if I call ReleaseHandle() the
native window is simply removed from the list (without restoring it to
the previous value).
In my eyes, this simply is a bug!
Thanks
Arthur