;======================================================
; _BatteryQuery()
; Return information on the Battery
; Sets @Error on error
; Returns an array:
; $array[0] = ACPower(0=offline, 1=online, 255=unknown)
; $array[1] = BatteryFlag(1=High, 2=Low, 4=Critical,
; 8=Charging 128=No Battery, 255=Unknown
; Use BitAnd to test, ie BitAnd($array[1],128)
; $array[2] = BatteryLife %(0-100, 255=unknown)
; $array[3] = Seconds left of charge, estimate(4294967295=unknown)
;======================================================
Func _BatteryQuery()
Local $SystemPower, $ret, $array[4]
; Setup $array and $SystemPower
$SystemPower = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong")
If @error Then
SetError(-1)
Return $array
EndIf
; make the DllCall
$ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($SystemPower))
If @error Then;DllCall Failed
SetError(-2)
$SystemPower = 0
Return $array
EndIf
If Not $ret[0] Then; GetSystemPowerStatus Failed
SetError(-3)
$SystemPower = 0
Return $array
EndIf
; Fill the array
$array[0] = DllStructGetData($SystemPower, 1); AC
$array[1] = DllStructGetData($SystemPower, 2); Battery Charge
$array[2] = DllStructGetData($SystemPower, 3); Battery Charge %
$array[3] = DllStructGetData($SystemPower, 5); Sec Battery Left
; free the struct
$SystemPower = 0
Return $array
EndFunc ;==>_BatteryQuery
|