1.wm_queryendsession
This message does not allow the application to exit directly, the message is primarily to ask if the application is ready to exit, and when all applications return true to the message, the system logs off or shuts down. If you want to quit the program, use the WM_CLOSE message!
Windows broadcasts a message wm_queryendsession to all the top-level windows when it shuts down, and its lparam parameter can distinguish between shutting down or logging off the user (lparam is endsession_logoff when logging off the user). Then Windows waits for all applications to return true for this message before it shuts down.
Therefore, as long as the main form of our application returns False,windows to this message, it will not shut down.
But it is not absolutely possible to prevent Windows from shutting down, because if an application calls ExitWindowsEx (ewx_poweroff| ewx_force,0); To shut down, I can not stop this program, because that call ExitWindowsEx, the system will not issue wm_queryendsession messages, the program will not prevent Windows shutdown.
2.wm_endsession
Windows sends Wm_endsession messages to each window message handler that previously received wm_queryendsession messages. If Windows cannot shut down the system because another program has returned 0 from Wm_queryendsession, then Wm_endsession's wparam parameter is 0. The wm_endsession message actually answers the question: I told Windows to end it, but did I really end it?
Windows System Message Collection-Gradual update in