|
-
Jan 30th, 2019, 03:19 PM
#1
[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?
-
Jan 30th, 2019, 04:32 PM
#2
Re: UserControl Terminate event not firing
Last edited by dz32; Apr 26th, 2019 at 11:09 AM.
-
Jan 30th, 2019, 04:39 PM
#3
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.
-
Jan 30th, 2019, 04:45 PM
#4
Re: UserControl Terminate event not firing
Last edited by dz32; Apr 26th, 2019 at 11:09 AM.
-
Jan 30th, 2019, 04:59 PM
#5
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.
-
Jan 30th, 2019, 05:18 PM
#6
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.
-
Feb 8th, 2019, 03:13 AM
#7
Member
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.
-
Feb 8th, 2019, 06:19 AM
#8
Re: [RESOLVED] UserControl Terminate event not firing
Last edited by dz32; Apr 26th, 2019 at 11:08 AM.
-
Feb 8th, 2019, 09:17 AM
#9
Re: UserControl Terminate event not firing
 Originally Posted by sabbath69
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.
-
Feb 8th, 2019, 09:52 PM
#10
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|