CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 1999
    Posts
    25

    How I can remove ALT+F4 from a dialog box?..

    Dear All,

    How I can remove ALT+F4 key from a dialog box?.. I dont want to quit the dialog box when user press ALT+F4 key?.....

    PL help me,....

    Regards,
    Kareem.





  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: How I can remove ALT+F4 from a dialog box?..

    you can trap the Form_QueryUnload event and check for the UnloadMode argument.
    If you don't want the user to be able to end your program just set the Cancel argument to false.


  3. #3
    Join Date
    May 1999
    Posts
    25

    Re: How I can remove ALT+F4 from a dialog box?..

    Hi,,

    Thanks for your reply. But It does not work properly. After I added Form_QueryUnload() function and set Cancel to false, user can quit the dialog by pressing ALT + F4. You pl check .... let me know that ...

    Regards,
    Kareem.


  4. #4
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How I can remove ALT+F4 from a dialog box?..

    Set it to True or 1.
    use Cancel = 1 . Cancel is defined as integer in QueryUnload and Unload events!!

    But this code will also stop the unload from 'X' of the Form Control menu!!

    private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)
    If UnloadMode = 0 then Cancel = 1
    Debug.print UnloadMode
    End Sub





  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: How I can remove ALT+F4 from a dialog box?..

    you need to set cancel to True!

    private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)
    Cancel = true
    End Sub



    now you won't be able to close the form


  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Another bit of Knowledge from the Past

    ;-)

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: How I can remove ALT+F4 from a dialog box?..

    Make sure that the form KeyPreview is set to True then try the following code:
    option Explicit
    Dim CancelAltF4 as Boolean

    private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)
    CancelAltF4 = false
    If KeyCode = vbKeyF4 then
    If Shift And 4 = 4 then
    MsgBox "ctrlv"
    CancelAltF4 = true
    End If
    End If
    End Sub
    private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)
    If CancelAltF4 then
    Cancel = true
    CancelAltF4 = false
    End If
    End Sub




  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Take a smile....

    Have a look at date this question was first posted....
    ;-)

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured