I suggest tackling one issue at a time.
Would it be possible to do without the subwindow and simply do everything with a portal on your layout? That would eliminate the issue of detecting a close window action altogether and might simplify your entire data entry process.
If you must go with a subwindow, I suggest using FMP advanced to modify the Close window menu for your subwindow's layout. You can modify the close window command to run your own script and you can then add whatever code you need to handle the accidental closure of the window. If you don't have advanced you can use the following code to disable the window closure controls:
Show/Hide Status Area [lock, hide]
Allow User Abort [off]
Pause/Resume Script [Indefinitely]
Now you add your own button to close the window and it can run your script for closing the window and thus can check for "accidental" window close situations. In button setup... you can specify that current scripts be exited in order to quit the above paused script. Also, the above script steps make your subwindow "modal" that is, the user will be prevented from interacting with other parts of your system until they close the subwindow.