News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to tell if Windows is sleeping

Started by sinsi, May 17, 2009, 04:47:02 AM

Previous topic - Next topic

sinsi

Just writing a simple wallpaper changer (pick a random jpeg every x minutes) and was wondering how to tell the power state, since
it seems a bit useless to change the wallpaper if Windows is asleep.

I am thinking of 3 things:
- WM_POWERBROADCAST with PBT_APMSUSPEND - set flag to 1
- WM_POWERBROADCAST with PBT_APMRESUMEAUTOMATIC - set flag to 0
- WM_TIMER - only change wallpaper if flag=0 and SPI_GETSCREENSAVERRUNNING=0

Are there any other things to consider?
Light travels faster than sound, that's why some people seem bright until you hear them.

Tedd

If the system is suspended, no programs will be running (including yours), so I'm not sure there's any point reacting to those notifications -- i.e. you'll never be attempting to change the wallpaper when the flag is set because it's only set upon suspension, and at that point your program won't be running.

Additionally, there's no need to change if the user isn't on their desktop (user switching means you can be logged in, running your program, but also be logged into another account and on this other account's desktop.)
No snowflake in an avalanche feels responsible.

sinsi

Quote from: MSDNWM_POWERBROADCAST messages do not distinguish between different low-power states
So my program could still be running (system not sleeping yet) but the screen has powered down?

I'm not worried about switching to another user since this program only has to work on one computer. Does anyone use fast user-switching?
Light travels faster than sound, that's why some people seem bright until you hear them.

hutch--

How about using a simple timer set to 10 second intervals so the processor usage is almost nothing, then set a time to change each background screen. If the machine is suspended it won't matter and will not effect anything.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

sinsi

I use a timer, every 5 minutes it kicks in and my program just picks another random jpeg and sets it.

I'm adding a logfile function to see what happens around the power stuff (and to find out why the background goes black occasionally  ::))
Light travels faster than sound, that's why some people seem bright until you hear them.