Results 1 to 5 of 5

Thread: Unloading Multiple Subclassed Usercontrols

  1. #1

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Question 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.



  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    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.

  3. #3
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,668

    Re: Unloading Multiple Subclassed Usercontrols

    Quote Originally Posted by some1uk03 View Post
    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

  4. #4

  5. #5
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    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
  •  



Click Here to Expand Forum to Full Width