找回密码
 加入
搜索
查看: 1798|回复: 2

[系统综合] 如何得到电池的电量?

[复制链接]
发表于 2010-4-15 15:45:50 | 显示全部楼层 |阅读模式
下面是三恨大侠给的一段判断系统使用的是外接电源,还是电池的代码,现在我想得到电池的电量,不帮有哪位能提供点帮助,在此十分感谢!!
$battery    = _BatteryQuery()


Switch $battery[0]
    case  0
        MsgBox(0,0,"AC Power is Offline")
    case  1
        MsgBox(0,0,"AC Power is OnLine")
    case Else
        MsgBox(0,0,"AC Power is Unknown")
EndSwitch


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
 楼主| 发表于 2010-4-16 08:23:16 | 显示全部楼层
解决了,谢三恨!!!!!!!!!
发表于 2010-4-16 13:51:04 | 显示全部楼层
怎么解决的啊,发出来让大家都学一下嘛。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-11 20:42 , Processed in 0.075052 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表