Results 1 to 10 of 10

Thread: [RESOLVED] UserControl Terminate event not firing

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Resolved [RESOLVED] UserControl Terminate event not firing

    User sabbath69 pointed out that with my Shell Tree Control, when the control is on a secondary form and that form unloads, the UserControl_Terminate event does not fire; it doesn't until the whole program is exiting. This is not the case with any of the other UCs I checked (besides my other UC, ucShellBrowse, which has the same issue). It seems like something that would happen because something needs to be freed; but cleanup can't occur if the terminate event isn't even fired.
    Any thoughts?

  2. #2
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,295

    Re: UserControl Terminate event not firing

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:09 AM.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl Terminate event not firing

    Just curious, does the form actually unload, or stays loaded, but hidden? Might want to place a Debug.Print in the form's terminate event.

    Also, in that other thread, the OP mentioned modality. Does this happen only when the secondary form is modal?

    You'd say Terminate does occur, but when the entire project is unloaded?

    Edited: dz32 & I posted about same time. Sounds like you have a starting point. Ignore above.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,295

    Re: UserControl Terminate event not firing

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:09 AM.

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,669

    Re: UserControl Terminate event not firing

    Hello, as dz32 already said I also traced the problem to the reference in the RegisterDragDrop API call.
    This reference needs to be freed in order to allow the UserControl to terminate.

    My suggestion is:

    in References
    Code:
    Private Const WM_SHOWWINDOW As Long = &H18
    in pvCreate
    Code:
    '    If hTVD Then Attach hTVD
    (the line was commented or removed)

    in ucWinProc
    Code:
    Select Case uMsg
        Case WM_SHOWWINDOW
            If Ambient.UserMode Then
                If wParam = 1 Then
                    If hTVD Then Attach hTVD
                Else
                    Detach
                End If
            End If
    It registers the dragdrop when the form is shown and unregister it when the form is unloaded.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: UserControl Terminate event not firing

    Yup that did it for both controls. Thanks, very much appreciated everyone.

    ps- modality didn't matter.

    Edit: pps- You don't need to define WM_ constants in ucShellTree or ucShellBrowse, or any oleexp project, as all of the documented ones are supplied in the WindowMessages enum since v3.7.
    Last edited by fafalone; Jan 30th, 2019 at 09:12 PM.

  7. #7
    Member
    Join Date
    Jul 2008
    Posts
    41

    Re: UserControl Terminate event not firing

    Eduardo/dz32 How were you guys able to trace the issue to that particular call. Did you use a tool to see open references? Very interested in how this was done, to assist me with future coding.

  8. #8
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,295

    Re: [RESOLVED] UserControl Terminate event not firing

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:08 AM.

  9. #9
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,669

    Re: UserControl Terminate event not firing

    Quote Originally Posted by sabbath69 View Post
    Eduardo/dz32 How were you guys able to trace the issue to that particular call. Did you use a tool to see open references? Very interested in how this was done, to assist me with future coding.
    Hello. I didn't use any tool. I used sucesive aproximations logic and temporarily removing lines of code.
    First I removed all the code in the ReadProperties event and checked if the Terminate event happened (it did).
    Then traced the problem to pvCreate, then to the line If hTVD Then Attach hTVD (always removing all, some, few or just one line of code and checking if the Terminate event happened or not when closing the form). Then, traced it to Attach, then to the RegisterDragDrop API call, and I saw the word Me there. Me was the reference that prevented the control to terminate.
    That reference had to be freed in order to allow the control to terminate.
    Last edited by Eduardo-; Feb 8th, 2019 at 10:47 PM.

  10. #10
    Member
    Join Date
    Jul 2008
    Posts
    41

    Re: [RESOLVED] UserControl Terminate event not firing

    Thanks dz32 and Eduardo!

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