Wednesday, April 29, 2009

Get Power Status

'Get Power Status



Private Type SYSTEM_POWER_STATUS

   
ACLineStatus As Byte

   
BatteryFlag As Byte

   
BatteryLifePercent As Byte

   
Reserved1 As Byte

   
BatteryLifeTime As Long

   
BatteryFullLifeTime As Long

End Type



Private Declare Function GetSystemPowerStatus
Lib "kernel32" _

(lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long



Private Sub Form_Paint()

Dim SPS As SYSTEM_POWER_STATUS

'get the battery power status

GetSystemPowerStatus SPS

Me.AutoRedraw = True


'show some information


Select Case SPS.ACLineStatus

Case 0

Me.Print "AC power status: Off Line"

Case 1

Me.Print "AC power status: On Line"

Case 2

Me.Print "AC power status: Unknown"

End Select


Select Case SPS.BatteryFlag

Case 1

Me.Print "Battery charge status: High"

Case 2

Me.Print "Battery charge status: Low"

Case 4

Me.Print "Battery charge status: Critical"

Case 8

Me.Print "Battery charge status: Charging"

Case 128

Me.Print "Battery charge status: No System Battery"

Case 255

Me.Print "Battery charge status: Unknown Status"

End Select

End Sub



 

No comments:

Post a Comment