onExit, onQuit, or anything like that?

Is there any way to always have a function run on application exit?

I was just about to put something that works when I call Application.Quit() from in the game when the player clicks to quit, but then...

I realized I don't know how to trap whether they are using the exit button on a windowed screen and not one of my own exit buttons from in the game.

Anyone know how to trap an exit to do something right before it quits out (set a registry variable for instance), no matter how the user quits out?

I think you want something like this: