VB6 测定手提式电脑是否在使用电池运行,并且测试出它的剩于电池量新建From1(窗体),新建Command1(按钮CommandButton),代码:
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
Private Sub Command1_Click()
Dim SysStatus As SYSTEM_POWER_STATUS, LifeTime As Double
GetSystemPowerStatus SysStatus
LifeTime = SysStatus.BatteryLifeTime
If LifeTime = -1 Then
MsgBox "Using AC Power"
Else
MsgBox LifeTime / 3600 & " hours remaining"
End If
End Sub