I have a problem with WM_ENDSESSION message. Namely I would like to exit from the main loop of the application (WindowProc) when the WM_ENDSESSION>
You don't need any special handling. Just call DefWindowProc instead of handling these messages.