Results 1 to 4 of 4

Thread: Intercept ALT+F4

  1. #1

    Thread Starter
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    The other day we all learned how to disable the close button
    with GetSystemMenu and RemoveMenu. They will allow you to
    disable (grey-out) the shutdown X in the control box. But
    this will still leave ALT+F4 as a means to shut down your app.

    Is there any way to intercept this keypress sequence to force
    the user into using a command button to quit the app? Or a
    way to disable ALT+F4 from closing your app?
    Donald Sy - VB (ab)user

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    There's a couple of things you can do. The first is to set the ControlBox property of the form to False but this will also remove the system menu completly.
    The second thing to do is to add code to the QueryUnload event.
    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If UnloadMode = vbFormControlMenu Then
            'the user is trying to close the window by
            'either keying ALT+F4 or by using the "X" button
            Cancel = True
        End If
    End Sub
    Have a look in MSDN library for other values you can check for in the QueryUnload event.

    Good luck!

  3. #3

    Thread Starter
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Thanks,
    The second method is the one I was looking for. And
    the MSDN library for this event has other useful tidbits that may come in handy.
    Donald Sy - VB (ab)user

  4. #4
    bwilson
    Guest

    Smile altF4 disable

    Thank you Joacim Andersson. Your answer worked immediately and solved a big problem for us!

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