-3

I tried to find information on this, but only found the WM_QUERYENDSESSION function. How can I use this to intercept reboot / shutdown messages?

import win32gui, win32con

msg = win32gui.GetMessage(None, 0, 0)
if msg and msg.message == win32con.WM_QUERYENDSESSION:
    print('EXIT')

Here is an example of my code, but when I run it it doesn't handle any actions. and does not intercept shutdown messages

bainki
  • 1
  • 1
    This is straight from the [documentation](https://learn.microsoft.com/en-us/windows/win32/shutdown/wm-queryendsession): *"A window receives this message through its `WindowProc` function."* Why did you avoid reading it? – IInspectable Jul 18 '20 at 12:36

1 Answers1

0

According to WM_QUERYENDSESSION: The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions. A window receives this message through its WindowProc function.

So this message will only take effect when sent by the application and accepted in the WindowProc function.

Zeus
  • 3,703
  • 3
  • 7
  • 20