VB.NET-Quellcode
- Private Structure SYSTEM_POWER_STATUS
- Public ACLineStatus As Byte
- Public BatteryFlag As Byte
- Public BatteryLifePercent As Byte
- Public Reserved1 As Byte
- Public BatteryLifeTime As Integer
- Public BatteryFullLifeTime As Integer
- End Structure
- Private Declare Function GetSystemPowerStatus Lib "kernel32" (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim power_status As SYSTEM_POWER_STATUS
- If GetSystemPowerStatus(power_status) = 0 Then
- lblACStatus.Text = "Error"
- Else
- Select Case power_status.ACLineStatus
- Case 0
- lblACStatus.Text = "Battery"
- Case 1
- lblACStatus.Text = "On line"
- Case 255
- lblACStatus.Text = "Unknown"
- End Select
- Dim txt As String = ""
- If power_status.BatteryFlag And 1 Then txt &= ", High (> 66%)"
- If power_status.BatteryFlag And 2 Then txt &= ", Low (< 33%)"
- If power_status.BatteryFlag And 4 Then txt &= ", Critical (< 5%)"
- If power_status.BatteryFlag And 8 Then txt &= ", Charging"
- If power_status.BatteryFlag And 128 Then txt &= ", No system battery"
- If power_status.BatteryFlag = 255 Then txt &= ", Unknown"
- If txt.Length > 0 Then txt = txt.Substring(2)
- lblBatteryStatus.Text = txt
- End Sub
- End Class
Fehler im Code gefixxt (von Chrisber)
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Chrisber“ ()