Results 1 to 6 of 6

Thread: One For the Gurus

  1. #1
    Guest

    Talking

    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

  2. #2
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    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.
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  3. #3
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305
    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

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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


  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    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]
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6
    Guest
    Looks like everyone loves a challenge

    You guys are awesome. Thx all.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width