|
-
Jan 14th, 2025, 10:52 AM
#1
Thread Starter
Frenzied Member
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?
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Jan 21st, 2025, 07:41 AM
#2
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.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 21st, 2025, 12:55 PM
#3
Re: Unloading Multiple Subclassed Usercontrols
 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
-
Jan 21st, 2025, 01:34 PM
#4
Re: Unloading Multiple Subclassed Usercontrols
If the window unsubclassed itself on WM_NCDESTROY this wouldn't happen.
-
Jan 23rd, 2025, 12:57 PM
#5
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|