WM_QUERYENDSESSION
The WM_QUERYENDSESSION message is sent when the user chooses to end the Windows session, or when an application calls the ExitWindows function. If any application returns zero, the Windows session is not ended. Windows stops sending WM_QUERYENDSESSION messages as soon as one application returns zero and sends WM_ENDSESSION messages, with the wParam parameter set to FALSE, to any applications that have already returned nonzero.
This message has no parameters.
An application should return nonzero if it can conveniently terminate; otherwise, it should return zero.
The DefWindowProc function returns nonzero when it processes this message.