The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: sinsi on May 17, 2009, 04:47:02 AM

Title: How to tell if Windows is sleeping
Post by: sinsi on May 17, 2009, 04:47:02 AM
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?
Title: Re: How to tell if Windows is sleeping
Post by: Tedd on May 17, 2009, 08:25:28 PM
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.)
Title: Re: How to tell if Windows is sleeping
Post by: sinsi on May 17, 2009, 11:46:53 PM
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?
Title: Re: How to tell if Windows is sleeping
Post by: hutch-- on May 19, 2009, 06:53:06 AM
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.
Title: Re: How to tell if Windows is sleeping
Post by: sinsi on May 20, 2009, 05:26:37 AM
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  ::))