Results 1 to 4 of 4

Thread: Why we hate GetSystemPowerStatus.

  1. #1

    Thread Starter
    Lively Member Zero's Avatar
    Join Date
    Feb 2000
    Posts
    101

    Why we hate GetSystemPowerStatus.

    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

  2. #2
    DaoK
    Guest
    VB Code:
    1. Private Type SYSTEM_POWER_STATUS
    2.         ACLineStatus As Byte
    3.         BatteryFlag As Byte
    4.         BatteryLifePercent As Byte
    5.         Reserved1 As Byte
    6.         BatteryLifeTime As Long
    7.         BatteryFullLifeTime As Long
    8. End Type
    9. Private Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
    10. Private Sub Form_Paint()
    11.     'KPD-Team 2000
    12.     'URL: [url]http://www.allapi.net/[/url]
    13.     'E-Mail: [email][email protected][/email]
    14.     Dim SPS As SYSTEM_POWER_STATUS
    15.     'get the battery powerstatus
    16.     GetSystemPowerStatus SPS
    17.     Me.AutoRedraw = True
    18.     'show some information
    19.     Select Case SPS.ACLineStatus
    20.         Case 0
    21.             Me.Print "AC power status: Offline"
    22.         Case 1
    23.             Me.Print "AC power status: OnLine"
    24.         Case 2
    25.             Me.Print "AC power status: Unknown"
    26.     End Select
    27.     Select Case SPS.BatteryFlag
    28.         Case 1
    29.             Me.Print "Battery charge status: High"
    30.         Case 2
    31.             Me.Print "Battery charge status: Low"
    32.         Case 4
    33.             Me.Print "Battery charge status: Critical"
    34.         Case 8
    35.             Me.Print "Battery charge status: Charging"
    36.         Case 128
    37.             Me.Print "Battery charge status: No system battery"
    38.         Case 255
    39.             Me.Print "Battery charge status: Unknown Status"
    40.     End Select
    41. End Sub

  3. #3
    DaoK
    Guest
    It return 255% to me to so I thinkg it's normal...

  4. #4

    Thread Starter
    Lively Member Zero's Avatar
    Join Date
    Feb 2000
    Posts
    101

    ...

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width