如何获取电源状态信息?
如何获取电源状态信息? 问题点数:100、回复次数:2Top
1 楼pandengzhe(无为之为 之 混迹苍生)回复于 2003-11-01 09:07:12 得分 95
1、SysInfo.ocx控件
2、GetSystemPowerStatus
Option Explicit
Private Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
Private Type SYSTEM_POWER_STATUS
ACLineStatus As Byte 'Checks to see if your connected to the walloutlet or not
BatteryFlag As Byte 'Battery status
BatteryLifePercent As Byte 'precentage left
Reserved1 As Byte 'Dont use
BatteryLifeTime As Long 'Total time left of your battery
BatteryFullLifeTime As Long 'Total UPtime of your battery
End Type
Private SysPower As SYSTEM_POWER_STATUS
'End Declares
Private Sub Form_Load()
'Property Get ACLineStatus() As Integer
'Returns a value that indicates whether or not the system is using AC power.
'Property Get BatteryFullLifeTime() As Long
'Returns a value that indicates the full charge life of the battery.
'Property Get BatteryLifePercent() As Integer
'Returns the percentage of full battery power remaining.
'Property Get BatteryLifeTime() As Long
'Returns a value that indicates the remaining life of the battery.
'Property Get BatteryFlag() As Integer
'Returns a value that indicates the status of the battery's charge.
GetSystemPowerStatus SysPower
Label1.Caption = Format$(SysPower.BatteryLifePercent / 100, "Percent")
Label2.Caption = Format$(Val(SysPower.BatteryLifeTime) * (1 / 3600), "##.0") & " Hours"
Label3.Caption = Format$(Val(SysPower.BatteryFullLifeTime) * (1 / 3600), "##.0")
'Label4.Caption = SysPower.ACLineStatus
If SysPower.ACLineStatus = 0 Then
Label4.Caption = "NON AC POWER"
ElseIf SysPower.ACLineStatus = 1 Then
Label4.Caption = "AC POWER"
ElseIf SysPower.ACLineStatus = 2 Then
Label4.Caption = "UNKNOWN AC POWER"
End If
'Label5.Caption = SysPower.BatteryFlag
If SysPower.BatteryFlag = 1 Then
Label5.Caption = "HIGH"
ElseIf SysPower.BatteryFlag = 2 Then
Label5.Caption = "LOW"
ElseIf SysPower.BatteryFlag = 4 Then
Label5.Caption = "CRITICAL"
ElseIf SysPower.BatteryFlag = 128 Then
Label5.Caption = "NO BATTERY"
ElseIf SysPower.BatteryFlag = 255 Then
Label5.Caption = "UNKNOWN"
End If
End Sub
Top
2 楼taosihai1only(无招胜有招)回复于 2003-11-01 14:38:02 得分 5
up
Top



