I'm having Tray application.
Onj FormCloseQuery I check if program should goto tray and instead of closing it I put it in tray (CanClose := False)
But if Windows tries to close my application because of Windows shutdown I want not to move my app into tray but to close it.
Win7 terminates my app, but XP doesn't close because my app remains in Tray.
How can I detect if Windows is some "shutting down" mode or not?
Thanks!
Your problems stem from the use of
OnCloseQuery
which is the wrong event to be using. Remy's answer explains how to workaround Windows shutdown being blocked by the default VCL end session message handling. And this in turn is caused by settingCanClose
toFalse
in theOnCloseQuery
event.That workaround will get the job done but there's a much simpler way to deal with this. Instead of stopping the form from closing, let it go ahead and close. Remove your
OnCloseQuery
event altogether. Replace it with anOnClose
event.This rather trivial bit of code is enough to make your app minimize to the tray when the main form is closed.