Unloading Multiple Subclassed Usercontrols
Hello All,
Recently i created a new UserControl that is subclassed and everything works fine.
However, when we have Multiple instances of the control, sometimes I get errors when closing/switching a Form in the IDE that the HWND no longer exists on UserControl_Terminate.
My research shows that this happens due to the order of which the unSubclassing happens and that it should be in reverse?
Any one have any ideas on this?
Re: Unloading Multiple Subclassed Usercontrols
If it were me, the first thing I'd do is make sure the ComCtl32.dll library was being used for subclassing. If not, I'd refactor to use it. That approach is much better than the SetWindowLong approach, and is much more robust to differences in "teardown" order.
Re: Unloading Multiple Subclassed Usercontrols
Quote:
Originally Posted by
some1uk03
the HWND no longer exists on UserControl_Terminate
Besides using Common Control subclassing, you can test whether a window still exists with the IsWindow API.
Code:
Private Declare Function IsWindow Lib "user32" (ByVal hWnd As Long) As Long
Re: Unloading Multiple Subclassed Usercontrols
If the window unsubclassed itself on WM_NCDESTROY this wouldn't happen.
Re: Unloading Multiple Subclassed Usercontrols
For example, two user control. CTL are designed to be added to Form 1.
In design mode. Controls need to be subclassed.
Does not compile to exe, nor does it run F5
The main code is triggered when the control resizes. Show, UserControl_Terminate Event
There is also a transparent windowless control.It responds to all events of mouse movement.
Add security subclassing in these places
If you close the window. All user controls are destroyed.
I selected Form 1. But the time the form was unloaded did not triggerIt is equivalent to being forced to end the process.
Events are incomplete and unsafe.