Changing the functionality of the close button?

The program I’m making allows users to save and load individual sessions. However, when the close button is pressed, the program just closes straight away.

83625-close-button.png

I want to make it so when the close button is pressed, the user is presented with a prompt asking them if they want to save their session before closing. Is there any way to change the functionality of the close button itself? Or is that just not possible?

I believe you can use OnApplicationQuit().