Python – Windows Shutdown Events

The problem here was that the HWND_MESSAGE window type doesn’t actually receive broadcast messages – like the WM_QUERYENDSESSION and WM_ENDSESSION.

So instead of specifying win32con.HWND_MESSAGE for the “parent window” parameter of CreateWindowEx(), I just specified 0.

Basically, this creates an actual window, but I never show it, so it’s effectively the same thing. Now, I can successfully receive those broadcast messages and shut down the app properly.

Leave a Comment