Click to See Complete Forum and Search --> : Why we hate GetSystemPowerStatus.
Zero
Dec 22nd, 2001, 08:04 PM
Greetings all.
I find that whenever I use the GetSystemPowerStatus API call it returns 255% battery life. This is obviously impossible, and it quite irritating. However, if I pop open Control Panel and look at the battery meter there- Magic! GetSystemPowerStatus starts reporting the right percentage until the next reboot.
My question is: How to I make GetSystemPowerStatus to behave properly through code? Is there some kind of flag I need to set with another API call?
~Zero the Inestimable
DaoK
Dec 22nd, 2001, 11:02 PM
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()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Hotmail.com
Dim SPS As SYSTEM_POWER_STATUS
'get the battery powerstatus
GetSystemPowerStatus SPS
Me.AutoRedraw = True
'show some information
Select Case SPS.ACLineStatus
Case 0
Me.Print "AC power status: Offline"
Case 1
Me.Print "AC power status: OnLine"
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
DaoK
Dec 22nd, 2001, 11:04 PM
It return 255% to me to so I thinkg it's normal...
Zero
Dec 23rd, 2001, 07:57 AM
Well that's just the point. 255% battery life is not normal.
Obviously the Windows Power Meter is initializing something that gets the API to work. What is it?
~Zero the Inestimable
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.