Power API

G

Gary''s Student

I am building an Excel alarm clock for a laptop. I am updating the display
with an OnTime event. One of the requirements is to autonomously detect if
the laptop switches from A/C power to its internal battery.

Has anyone come across an API that will return the power state? Say TRUE if
A/C, FALSE if battery?

Thanks for any leads.
 
J

John Bundy

Sorry i don't know who to give credit to as i found this some time ago and
modified it. Enjoy!

Declare Function GetSystemPowerStatus& Lib "kernel32" (lpSystemPowerStatus
As _
SYSTEM_POWER_STATUS)

Type SYSTEM_POWER_STATUS
ACLineStatus As Byte
BatteryFlag As Byte
BatteryLifePercent As Byte
Reserved1 As Byte
BatteryLifeTime As Long
BatteryFullLifeTime As Long
End Type

Public SysStat As SYSTEM_POWER_STATUS
Public Ret As Boolean
'***************************
' Place in command button click
Private Sub Command1_Click()
Ret = GetSystemPowerStatus&(SysStat)
MsgBox Ret
MsgBox "AC Status = " & SysStat.ACLineStatus
End Sub
'*****************************

Ret is True if successful.
ACLineStatus =0 if offline (battery?), 1 if online (AC Power, also desktop),
255 if unknown (Aliens?)
 
J

Jim Cone

Maybe...

Private Declare Function GetDevicePowerState Lib "kernel32.dll" _
(ByVal hDevice As Long, ByRef pfOn As Long) As Long
http://msdn2.microsoft.com/en-us/library/aa372690.aspx

Private Declare Function GetSystemPowerStatus Lib "kernel32.dll" _
(ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
http://msdn2.microsoft.com/en-us/library/aa372693(VS.85).aspx

--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"Gary''s Student"
wrote in message
I am building an Excel alarm clock for a laptop. I am updating the display
with an OnTime event. One of the requirements is to autonomously detect if
the laptop switches from A/C power to its internal battery.

Has anyone come across an API that will return the power state? Say TRUE if
A/C, FALSE if battery?
Thanks for any leads.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top