devxlogo

Application Termination

Application Termination

Question:
I have a message box that comes up to warn the user that they are terminating the application as it normally should be left running. I want to know how to stop that message if the machine is performing a shutdown. At the moment the event is fired every time. I have the event in the form.unload event of the main form so I can cancel the unload if the user does not want to close the application.

Answer:
Use the QueryUnload event, it has a parameter called unloadMode which tells you why the app is being shut down. The following are the possible values.

vbFormControlMenu: The user clicked the Close button on the Control menu on the form.
vbFormCode: The Unload statement is called from code.
vbAppWindows: The current Windows session is ending.
vbAppTaskManager: The Task Manager is closing the application.
vbFormMDIForm: An MDI child form is closing because the MDI parent form is closing.
vbFormOwner: A form is closing because its owner form is closing (owner is new to vb6, a form’s owner is specified as the Owner argument of the Show method).

See also  Essential Measures for Safeguarding Your Digital Data
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist