Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1677
Number of posts: 4766

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
The Close Window Button Posted by GiftedSailor on 8 Mar 2011 at 7:30 PM
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?

Report
Re: The Close Window Button Posted by GWS01 on 9 Mar 2011 at 6:05 AM
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 ..

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


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


Report
Re: The Close Window Button Posted by GiftedSailor on 9 Mar 2011 at 11:05 AM
Thanks for the tip. After trying several that seemed likely I finally found that Form > QueryUnload was the answer.

Thanks again
Report
Re: The Close Window Button Posted by GWS01 on 9 Mar 2011 at 11:51 AM
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





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.