Trapping Exit from Dos

How do I install a exit procedure for a DOS application written in BP7
running in a DOS shell under Windows?  I need to trap this event when
the application is killed by the user closing the DOS prompt window.  Is
there any way I can detect within my DOS application that it is being
killed when the DOS prompt window is closed?

dien.