VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



QueryUnload

by Riaan Aspeling (14 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (38 Votes)

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

Side Effects
Make sure you DO have a way of closing your form/app
API Declarations

Rate QueryUnload

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
   End
   
  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)
   End
   
  Case vbFormMDIForm 'Value 4
'This code is called from the parent form
   cancel = False
 End Select
End Sub

Download this snippet    Add to My Saved Code

QueryUnload Comments

No comments have been posted about QueryUnload. Why not be the first to post a comment about QueryUnload.

Post your comment

Subject:
Message:
0/1000 characters