Wednesday, September 10, 2014

How to Detect Unload-Event Source in VB6

Occurs before a form or application closes. When an MDIForm object closes, the QueryUnload event occurs first for the MDI form and then in all MDI child forms. If no form cancels the QueryUnload event, the Unload event occurs first in all other forms and then in an MDI form. When a child form or a Form object closes, the QueryUnload event in that form occurs before the form's Unload event.

Syntax
Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)
Private Sub MDIForm_QueryUnload(cancel As Integer, unloadmode As Integer)
The QueryUnload event syntax has these parts:
e QueryUnload event syntax has these parts:
PartDescription
cancelAn integer. Setting this argument to any value other than 0 stops the QueryUnload event in all loaded forms and stops the form and application from closing.
unloadmodeA value or constant indicating the cause of the QueryUnload event, as described in Return Values.


Return Values
The unloadmode argument returns the following values:
ConstantValueDescription
vbFormControlMenu0The user chose the Close command from the Control menu on the form.
vbFormCode1The Unload statement is invoked from code.
vbAppWindows2The current Microsoft Windows operating environment session is ending.
vbAppTaskManager3The Microsoft Windows Task Manager is closing the application.
vbFormMDIForm4An MDI child form is closing because the MDI form is closing.
vbFormOwner5A form is closing because its owner is closing.

Example:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = 0 Then  'X button was clicked
        End
    End If
End Sub

No comments:

Post a Comment