With FMP advanced, you can customize the menu so that closing the window triggers a script to close the window and do any other steps you need done. Include a halt script step in this script to halt the original paused script.
Without FMP advanced, you can use the script step "Allow User Abort" to keep the user from canceling the script or closing the window by clicking the close button on the window. You can then place your own close or cancel button on it to script whatever actions are needed along with closing the window. When you add this button, specify that current scripts be halted in Button setup to halt the paused script.
To keep anything from happening when the user continues the paused script, put it inside an infinite loop.
The above "halt script" methods are what get your user out of this loop.
The subject is different from your actual post. There are different answers. For your subject line, if you have FMP Advanced, then you can use Custom Menus to override the Close Window script.
For your post, you can use a paused loop to make the window act like a Modal window.
Allow User Abort [ Off ]
Pause [ Indefinitely ]
Now your button that you use now to close teh window, when you go to choose the script for the button the default option it to pause the current script. Change it to either Exit or Halt.
*Edit - Didnt see Phil's reply.