When the user presses a close Button that I created, some tasks are performed before exiting. However, if the user clicks on the [X] button in the top-right of the window to close the window, I cannot perform these tasks. 
How can I override what happens when the user clicks [X] button?
 
     
     
     
    