am currently building a program that runs as a background process, but due to the loops inside it, Windows fails to Close it when it goes into either shutdown or LOGOFF mode. It is a GUI program that uses WINMAIN but without a GUI interface. Can you tell me how to make the program detect when the computer is going to shutdown so that it can terminate imediately.