Saving in window mode..

Blitz3D Forums/Blitz3D Beginners Area/Saving in window mode..

I'm making a game that saves some Ints to a .dat file when the user presses Esc and ends the program. That works fine, but the game is in windowd mode and when the user clicks on the little X instead of pressing Esc, it doesn't run the code the saves before quitting. How can I save my game when you press the little X?
How I am saving the game:
While Not KeyHit(1)

Wend
SaveData()
End