Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB5,VB6
Expertise: Intermediate
Aug 18, 2001

GetBatteryTime - Get the life time of a notebook's battery

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

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


' Get the life time of a notebook's battery.
' Returns -1 if the computer is not a notebook or if it's not using a battery
' Param values:
'   0 -> return the lifetime in seconds (by default)
'   1 -> return the lifetime in minutes
'   2 -> return the lifetime in hours
' Example:
'   MsgBox "Left minutes:" & GetBatteryTime(1)

Private Function GetBatteryTime(Optional ByVal ResultFormat As Integer) As _
    Double
    Dim SysStatus As SYSTEM_POWER_STATUS
    GetSystemPowerStatus SysStatus
    
    ' return the number of seconds
    If ResultFormat = 0 Then
        GetBatteryTime = SysStatus.BatteryLifeTime
    ' return the number of minutes
    ElseIf ResultFormat = 1 Then
        GetBatteryTime = SysStatus.BatteryLifeTime / 60
    ' return the number of hours
    Else
        GetBatteryTime = SysStatus.BatteryLifeTime / 3600
    End If

End Function
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date