2

I am writing c++ code. I am new to c++. I want to find system power state i.e if its offline/sleep/online etc i am trying to use SYSTEM_POWER_STATE enumeration . But can't find how to use it if some can write a short example or post a helpful link .

Thanks in advance

triclosan
  • 5,578
  • 6
  • 26
  • 50
Ann
  • 23
  • 1
  • 5

1 Answers1

1

There's a wealth of info in MSDN about Power management.

List of power management functions with descriptions:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa373163(v=vs.85).aspx

And the usage samples:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa373243(v=vs.85).aspx

However, your question is a little strange: while you're sleeping you're... sleeping ! You can switch the system to Suspend mode, but your software is not running while the system sleeps. So please clarify your question if you want some more specific info. If you're writing a system service or a driver, this makes more sense, but still it is not clear from the question.

To get the power status (battery load, power source) use the GetSystemPowerStatus.

And one more thing. If you're talking about the Windows CE, then here you go: GetSystemPowerState. You didn't tell about WinCE either :)

Viktor Latypov
  • 14,289
  • 3
  • 40
  • 55
  • yes you are so right how can i get a system state when system is sleeping itself . I guess i need some further clarification of requirements . Thank you – Ann May 30 '12 at 10:16
  • 1
    If the system is sleeping then you can't do anything. It's like asking: How do i know if a person is hungry if he's sleeping? – RedX May 30 '12 at 10:29
  • You need an external PC to know that the other PC/SmartDevice is sleeping. Make a UDP heartbeat packet flow and see if this flow interrupts. – Viktor Latypov May 30 '12 at 10:34