When Windows are being shutdown or restarted, all runnig applications are closed of course.
This can be dangerous, because you can lost your unsaved documents. But
there is an easy way to detect, that Windows wants to shutdown and your
application can do everything necessary to close properly.This “trick” is pretty simple.