|Preventing a form from unloading|
|By: Unknown Date: 24/09/1998|
How often have you wanted to keep a user from unloading a form through the control-box? For that matter, how many times have you been frustrated because Windows shut down without your program cleaning up behind itself? Well, no more.
The trick, of course, is in the QueryUnload event for the given form. Any time your form is about to be unloaded, Windows triggers this event within your program to basically "ask permission" to terminate it. Windows will also provide a little information. If you want your program to shut down quietly if your program is attempting to close it, but not the Task Manager. There are 5 trappable ways a form can be unloaded. They are:
Below is the routine to determine how the program is being unloaded. In the example below, the only way the form can be unloaded is if the program itself has unloaded it.
|Sub Form_QueryUnload (Cancel As Integer, UnloadMode As
On Error Resume Next
If UnloadMode <> 1 Then
Cancel = True
|Visual Basic Programming Zone is a website by
Lorenzo Dalla Vecchia.
Webmaster's e-mail: firstname.lastname@example.org
Hosted by InWind: www.inwind.it