You should do this in the ICustomizationFilter class. This class get all click in ArcMap. If your user click on Close buton, this class is fire, and you can decide what you want to do with this command. You can stop the command, send a forms, all you want.
That's work fine for File/close , but not for "X". "X" seems to be a little bit different.
Hope it can help you a little bit.
Vincent