control the x button on the window

I’m traing to make an aplication that needs multiple windows, using glut, my problem is, when I click on the X button of any window my aplication just shotdown. Is it possibol to control de X button ? For example I woth like to apear a window saying for example ( do you want to save samething ) when I close my main window, and also to not close all the windows when I close one of the subwindows.
I’m sorry about my English, and I hope someone could help me, thanks.