Search Tools Links Login


Posted: 2002-06-01
By: ArchiveBot
Viewed: 125

Filed Under:

VB6 Code Cache

No attachments for this post

How to prevent a form/app from unloading , even if you use the taskmanager? Then try this code... (It works for me ;)

Original Author: Riaan Aspeling

Side Effects

Make sure you DO have a way of closing your form/app


Private Sub Form_QueryUnload(cancel As Integer, UnloadMode As Integer)

'To cancel the unload make the cancel = true. Don't do it
'on the vbAppTaskManager one though.

Dim ans As String
Select Case UnloadMode
  Case vbFormControlMenu 'Value 0
'This will be called if you select the close from the little icon
'menu on top and left of the form.
   cancel = False
  Case vbFormCode 'Value 1
'This will be called if your code requested a unload
   cancel = False
  Case vbAppWindows 'Value 2
'vbAppWindows is triggered when you shutdown Windows and your app is still
'running. Added by Jim MacDiarmid
   cancel = False
  Case vbAppTaskManager 'Value 3
'You have to allow the taskmanager to close the program, else you get
'that nasty 'App not responding, close anyway' dialog :<
'The clever way arround it would be to restart your program
'This would be used for a password screen!
   cancel = False
   x = Shell(App.Path & "" & App.EXEName, vbNormalFocus)
  Case vbFormMDIForm 'Value 4
'This code is called from the parent form
   cancel = False
End Select
End Sub

Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.