Finishing program on exit windows

Hello, I've got a question, let's say I've got a program thats supposed to be working until the user has decided to exit or logout windows. Now, how to make the program do it's last function (for example saving some content to a file) after the user has pressed shutdown or logout ?

In other words I am looking for the command that will tell my program that the user has pressed shutdown, so it is supposed to save the content before the computer actually shuts down.
If you are in Windows
Perhaps, this may be helpful to you.

http://stackoverflow.com/questions/981306/how-to-detect-whether-windows-is-shutting-down-or-restarting

And BTW, you may want to post this question in Windows Programming (or UNIX/Linux Programming) section!

EDIT:
http://www.cplusplus.com/forum/general/11433/
Last edited on
When windows is shutting down (clean) it sends the WM_QUERYENDSESSION message to all of the Applications message queues to close. Since this message is recieved through the WinProc Callback function it should be enough for you to add an entry to handle this message.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa376890(v=vs.85).aspx
Topic archived. No new replies allowed.