How can I make a program detect if the computer is being shut down? That way I can make my editor save it's data before the system closes it.

Thanks, August.