CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2004
    Posts
    130

    Want Alt+F4 to close my app

    Hi all

    For some reason Alt+F4 doesnt close my application.

    I would like the application to behave predictably and close when the user presses these keys.

    I have the KeyPreview set to True in the form properties.

    How come this key combination doesnt work? I thought it was a Windows default feature.

    Any pointers would be appreciated

    Many thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792

    Re: Want Alt+F4 to close my app

    What's the code you have in your form_keypress event?
    Be nice to Harley riders...

  3. #3
    Join Date
    Feb 2004
    Posts
    130

    Re: Want Alt+F4 to close my app

    Absolutely nothing.

    Thanks for getting back to me

    Adrian

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Want Alt+F4 to close my app

    Strange. Alt+F4 works for me whether KeyPreview is true or false...

    What code have you got in your form? Does Alt+F4 relly absolutely nothing?

  5. #5
    Join Date
    Feb 2004
    Posts
    130

    Re: Want Alt+F4 to close my app

    hi

    yes that's very odd.

    the app has about six forms. Some have virtually no code at all. more of a message box really. just an ok button that unloads that message form.
    Even these small forms don't close using alt+F4.

    I will gladly post the code for the other forms but there is tons of it and none relate to sendkeys or any reference to key strokes. mainly just simple calculations.

    perhaps I could do some code to invoke a window close if the alt+F4 is pressed.

    any suggestions on how I would go about that?


    I did think my situation was odd as on seraching the forum I found everyone wanted to disable the alt+f4 +hich rather pointed to the fact that it usually wrks by default.

    thanks for your continued help chaps

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Want Alt+F4 to close my app

    I'm thinking about 2 possible reasons ( which you have to confirm, as I have no clue as to what your forms look like )

    Issue 1
    Is the particular form's ControlBox property set to False ¿

    Issue 2
    Is the particular form's BorderStyle property set to 0 - None ¿

  7. #7
    Join Date
    Feb 2004
    Posts
    130

    Re: Want Alt+F4 to close my app

    ah!!! yes the control box is set to false on all forms.

    I will set to true and report back.

    thanks hamster, I have a feeling you might be on to it.

    regards
    adrian

  8. #8
    Join Date
    Feb 2004
    Posts
    130

    Re: Want Alt+F4 to close my app

    Well that is that sorted out.

    yes setting the control box to true re-instates the alt+f4 function.

    many thanks

    It begs another question:-

    I set the control box to false to ensure that the user closed the app via my close button, thus allowing code to fully unload the visable window and any that may be running as hidden.

    How can I detect if the X button in the control box has been clciked instead of my close button?



    Adrian

  9. #9
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Want Alt+F4 to close my app

    The form has an event. I think it is Query_UnLoad. That gets fired anytime the form starts to close.

  10. #10
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Want Alt+F4 to close my app

    Yes. And to be more specific, the parameter UnloadMode defines the mode of how unload was forced.
    0 = close button or alt-f4
    1 = Unload Me command
    Are there more?

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