views:

341

answers:

3

Hello,

I'd like to check if the system is in standby mode, is there any Win32 API for that? I'm not sure if it's the same as the sleep mode.

There's some code that gets executed in my app, which causes it to hang when coming out of standby (it's executed during the standby mode), so I'd like to avoid running that code when the computer is sleeping/standing by.

Thanks in advance!

Dennis

edit: perhaps it's impossible, because the program shouldn't be running as was pointed out in the answer below, so I'll count that as an answer :)

+3  A: 

When the system is in standby mode, then no program will be running, so the following would be ok:

int is_in_standby() {
  return 0;
}

Or am I missing something?

Joachim Sauer
My program seems to be running, or at least it was reported by a user that it pops up a message box (as it should, because there's something that needs attention), but after that it completely hangs. I'd like to know if the system is in standby and not have that message box come up.
dennisV
saua is right; if the system is in stand-by mode, then your app won't even do a pop-up. Your app hang is probably due to something else.
Brian
Yes, in theory it shouldn't popup, but in practice, when the user comes out of standby - there is the box, which must've come somehow during standby. I'll try to reproduce it on my machine...
dennisV
I know what you're talking about, I've seen that before (even in hibernate mode, with power removed). My guess is that processes are getting time slices before the system is fully back out of standby (not while actually in it, but during the return).
Brian Knoblauch
Yes, sounds right. I doubt that this state can detected, can it?
dennisV
@dennisV you might be able to detect it by checking if the system time jumps ahead, but it would be a hack at best.
Eric Haskins
Thanks EHaskins - I'm still hoping to find some way of doing this "properly", but if all else fails, then it's down to such hacks :)
dennisV
+1  A: 

As far as I know no code is running during Windows's Standby mode. Besides the RAM everything is off. The bug in your code might be caused by the window messages after the computer wakes up again.

Richard J. Terrell
Most probably, it's the screen dimensions. I wonder if they're reset to 0x0 during standby, because the window position after coming out of standby (a popup window) is in the top-left corner, instead of the bottom-right. But that window shouldn't up, because the code shouldn't be running in standby?
dennisV
A: 

If your program is running you aren't in standby.

I think what you want to do is handle the WM_POWERBROADCAST messages. These will tell you when the system is changing the power state, and prior to Vista you can be evil and veto a powerdown if you want.

Jim In Texas