-
I have a small app that runs with it's icon in the system tray (down by the clock). When you click on the icon it brings up a small form to with some preferences on it.
What I want to do is hook or subclass or do something to the "X-to-close" button on the form so that instead of actually closing the app it minimizes it (the user has an Exit option in the menu). I just want to prevent the user from actually closing the app when all he's trying to do is close the preference window.
I know I can just make the form without a control box, but that wouldn't be as cool.
Thanks, John
-
Here it is, and by the way, not for gurus, believe me :)
Code:
Private Sub Form_Unload(Cancel As Integer)
'your code for making it in systray
End Sub
Hope that helps.
-
You don't want to use form_unload because then you never can end the program because you end the program with form_unload. It's like initiating a loop. Anyway, what you want it QueryUnload.
Try this:
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = 1
Me.WindowState = vbMinimized
End Sub
QueryUnload is activated when you press the X, so this just cancels and minimizes the form. Pretty simple.
bob
-
This is one of those things that you'd think would be really hard, but it isn't.
try this
Code:
'This event fires when the user tries to unload the form
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'This instructs it not to unload
Cancel = vbCancel
'this minimises it
Me.WindowState = vbMinimized
End Sub
-
Subclass? No need to!
Just add some code to the Query_Unload from the Form and if the boolean isn't present, minimize the app. Like this.
Code:
Public CancelMe As Boolean
Private Sub mnuExit_Click
CancelMe = True
Unload_Me
End sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If CancelMe = False Then
'Cancel the window-unloading process
Cancel = 1
'Minimize the window
Me.WindowState = 1
End if
End Sub
Hope it helped.
*wow* in the time I was posting/testing 4 people had replied, but still, I think my code is the best because you're still able to exit the prog via the menu. :)
btw, I'm no guru yet but I couldn't resist posting :)
[Edited by Jop on 09-06-2000 at 11:15 AM]
-
Looks like everyone loves a challenge ;)
You guys are awesome. Thx all.