C
Claes Bergefall
I'm trying to temporarily subclass a window and tried using
the NativeWindow class, but...
I found some weird behaviour with the ReleaseHandle method
in the NativeWindow class. It seems as if that method messes
up the internal state of the application.
To reproduce the problem I created a simple Form with a
button on it, and placed the following code in the button click
event handler:
Dim h As IntPtr
Dim ctrl As Control
Dim wnd As New NativeWindow
wnd.AssignHandle(Me.Handle)
h = Me.Handle
ctrl = Control.FromHandle(h)
wnd.ReleaseHandle()
h = Me.Handle
ctrl = Control.FromHandle(h)
The first call to Control.FromHandle works as expected
and returns the form instance (Me). The second one doesn't; it
returns null. Both calls to Me.Handle works correctly though.
If you call the above code twice (i.e. press the button twice)
the message handling for the form breaks down! It doesn't paint
correctly, you can't close it fully etc
Found a thread about this that states that this problem exists in 1.0
but has been fixed in 1.1. Well, I use 1.1 and it doesn't look like
it has been fixed. Here is the thread:
http://groups.google.se/groups?hl=s...%20ReleaseHandle&as_ugroup=*dotnet*&lr=&hl=sv
Ideas or comments anyone?
/claes
the NativeWindow class, but...
I found some weird behaviour with the ReleaseHandle method
in the NativeWindow class. It seems as if that method messes
up the internal state of the application.
To reproduce the problem I created a simple Form with a
button on it, and placed the following code in the button click
event handler:
Dim h As IntPtr
Dim ctrl As Control
Dim wnd As New NativeWindow
wnd.AssignHandle(Me.Handle)
h = Me.Handle
ctrl = Control.FromHandle(h)
wnd.ReleaseHandle()
h = Me.Handle
ctrl = Control.FromHandle(h)
The first call to Control.FromHandle works as expected
and returns the form instance (Me). The second one doesn't; it
returns null. Both calls to Me.Handle works correctly though.
If you call the above code twice (i.e. press the button twice)
the message handling for the form breaks down! It doesn't paint
correctly, you can't close it fully etc
Found a thread about this that states that this problem exists in 1.0
but has been fixed in 1.1. Well, I use 1.1 and it doesn't look like
it has been fixed. Here is the thread:
http://groups.google.se/groups?hl=s...%20ReleaseHandle&as_ugroup=*dotnet*&lr=&hl=sv
Ideas or comments anyone?
/claes