Link to home
Start Free TrialLog in
Avatar of dapperry
dapperry

asked on

Determine s Shutdown|Close All Programs

I have a little program that runs in the system tray.  In the Form_Unload event I have a confirmation message box, which asks the user if they really want to exit.  However, if the User does a shutdown, restart, or "Close All Programs and Login in as another user" it still gives the confirmation msgbox.  I don't want this to happen.  So how do I tell if the user or the system is trying to shut the programs down?

:) dapperry
ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can tell how the unload was invoked by looking at the UnloadMode parameter in QueryUnload.  In your case, you want to confirm exit in vbFormControlMenu and vbFormCode, but not in vbAppWindows.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Select Case UnloadMode
    Case vbFormControlMenu
        'The user chose the Close command from the Control menu on the form.
    Case vbFormCode
        'The Unload statement is invoked from code.
    Case vbAppWindows
        'The current Microsoft Windows operating environment session is ending.
    Case vbAppTaskManager
        'The Microsoft Windows Task Manager is closing the application.
    Case vbFormMDIForm
        'An MDI child form is closing
    End Select
End Sub
Avatar of dapperry
dapperry

ASKER

Thanks,  I guess thats one form event I just never got around to looking at!  

:) dapperry