Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing application after user clicks on Windows X box

Status
Not open for further replies.

wabeers

Programmer
Dec 3, 2001
6
0
0
US
How can I gain control after a user clicks on the Windows "X" button on the top right corner to shut down the application. If a user clicks on the Windows "X" botton the application is still in memory ie. the task manager still shows it even though the forms disappear. This happens when the user ignores the EXIT button that I provide.

Thanks for any help.

Bill Beers
 
The "X" will trigger a QueryUnload then a Unload event. Do what you want there....ie cleanup code.
 
Thanks for the help - I just coded an "End" statement in the QueryUnload event and the application was flushed from memory.

Bill
 
SurvivorTiger:
That will work OK in a very simple program. However you are liable to generate memory leaks. as your forms are not unloaded, and any activex controls will not be unloaded.
There have been several discussions on memory leaks and program closes in this forum.
VB Help says:

Note The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.

The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created from your public class modules and no code executing.


Take SemperFiDownUnda 's advice and do the right thing, that is write your cleanup code! Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top