Intercepting sleep msg Windows 7

My software (still in RealStudio) controls an experiment that could last for hours. During the experiment I would like to stop the computer from going into sleep-mode/hibernation/power-save. I know that there used to be a msg broadcasted from windows xp (something like WM_POWERBROADCAST). Is that still around? Can I intercept it?
Any suggestions about that?

Windows Functionality Suite (WFS) https://github.com/arbp/WFS (I think this is the main URL)? has examples of overriding the WndProc function for a window class.

You can then watch and respond to WM_ commands.

I use this technique and it works well.

Be careful that your WndProc function must be well-behaved, as it gets called a ton and it needs to return True or False appropriately, and don’t do anything silly such as putting a MsgBox inside it.

Very true. Get in, get out. The message you’re processing might have been sent synchronously by another app that’s blocking until you respond. It must also not be an instance method, e.g. a method of a window or class instance. Win32 callbacks must be shared or module methods.

I’d recommend looking into the WM_QUERYENDSESSION message.

I’ve written quite a bit of window message processing code in the last few months, so if you get stuck feel free to bend my ear. :slight_smile: