Trying to capture when the user clicks end task from the task manager, and when the user logs off of windows, in order to perform clean-up tasks before closing the application.
After reading this answer&comments and this answer I got the following conclusions:
- if my application is a GUI application, I should handle the message
WM_CLOSE
andWM_ENDSESSION
in my message loop, which will cover both cases (end task and log off). - If my application is a console application, I should use
SetConsoleCtrlHandler
to handleCTRL_CLOSE_EVENT
andCTRL_LOGOFF_EVENT
, which will handle both cases.
Are my conclusions correct?
If my app doesn't have any window nor a message loop nor a console attached (It's technically a background process that is compiled with the -mwindows
flag in MinGW gcc in order to hide the console window):
- How to capture end task and log off in this case?