Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

The Close Window Button

GiftedSailorGiftedSailor Posts: 5Member
I'm working in VB5. In my program I have a menu item to close the program but it checks to see if I want to save my data before it closes. How can I make the the close window button do the same before closing the program?

Comments

  • GWS01GWS01 Posts: 10Member
    Hi giftedsailor,

    Sorry I can't answer your question exactly. I've looked through several VB books that I have, including Microsoft's own, and none of them mention how the caption bar icons are treated.

    Without loading VB5 (which I haven't done for many years), I can't check it out - but if you click on the Form to bring up the code editor, you will probably find the event code for Private Sub Form_Load().

    Somewhere around there you might be able to spot an option to set up an event handler for when the Form_Close is clicked - then you could place your shut down code in that routine.

    Certainly, when you click the 'X' icon, a message will be sent to Windows which you should be able to intercept.

    In the Basic I'm currently using, you would use ..

    [code]
    sub msghandler
    select @class
    case @idclosewindow
    ' closing the window
    .... whatever code you wish to execute ...
    closewindow win
    endselect
    return
    [/code]

    One of the problems with GUI systems like VB and RealBasic, is they don't let you get at all that's going on under the hood in Windows.

    I like to have access to all of it, as in the bit of code above.

    all the best,

    Graham


  • GiftedSailorGiftedSailor Posts: 5Member
    Thanks for the tip. After trying several that seemed likely I finally found that [b]Form > QueryUnload[/b] was the answer.

    Thanks again
  • GWS01GWS01 Posts: 10Member
    Ah, of course - not something that springs readily to mind .. and not even mentioned in several of my books.

    It is in the Microsoft literature though, with the caveat that ..

    'Important: Under certain circumstances, a form will not receive a QueryUnload event. If you use the End statement to terminate your program, or if you click the End button (or select End from the Run menu) in the development environment.'

    Glad you found a solution.

    Best wishes,

    Graham


Sign In or Register to comment.