HOLA!!! :D
Les dejo el codigo de la api segun la apiguide 3.7:
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 Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
Private Sub Form_Paint()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Hotmail.com
Dim SPS As SYSTEM_POWER_STATUS
'get the battery powerstatus
GetSystemPowerStatus SPS
Me.AutoRedraw = True
'show some information
Select Case SPS.ACLineStatus
Case 0
Me.Print "AC power status: Offline"
Case 1
Me.Print "AC power status: OnLine"
Case 2
Me.Print "AC power status: Unknown"
End Select
Select Case SPS.BatteryFlag
Case 1
Me.Print "Battery charge status: High"
Case 2
Me.Print "Battery charge status: Low"
Case 4
Me.Print "Battery charge status: Critical"
Case 8
Me.Print "Battery charge status: Charging"
Case 128
Me.Print "Battery charge status: No system battery"
Case 255
Me.Print "Battery charge status: Unknown Status"
End Select
End Sub
El problema es que si tengo la bateria cargando me devuelve 9 como flag y no 8 :S.
Saben porque sera?
Muchas gracias por su ayuda :)
HOLA!!!
SO' BOLUDO' ?
XD
8 de bateria cargando
+
1 de bateria con carga alta
=
9
Pone asi y va a funcionar:
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 Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
Private Sub Form_Paint()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Hotmail.com
Dim SPS As SYSTEM_POWER_STATUS
'get the battery powerstatus
GetSystemPowerStatus SPS
Me.AutoRedraw = True
'show some information
Select Case SPS.ACLineStatus
Case 0
Me.Print "AC power status: Offline"
Case 1
Me.Print "AC power status: OnLine"
Case 2
Me.Print "AC power status: Unknown"
End Select
If SPS.BatteryFlag And 1 Then Me.Print "Battery charge status: High"
If SPS.BatteryFlag And 2 Then Me.Print "Battery charge status: Low"
If SPS.BatteryFlag And 4 Then Me.Print "Battery charge status: Critical"
If SPS.BatteryFlag And 8 Then Me.Print "Battery charge status: Charging"
If SPS.BatteryFlag And 128 Then Me.Print "Battery charge status: No system battery"
If SPS.BatteryFlag And 255 Then Me.Print "Battery charge status: Unknown Status"
End Sub
GRACIAS POR LEER!!!
y como iba a saber yo que se sumaban? :P
Gracias mi buen amigo :)
PD: como usaste el and? no entiendi :P
@Elemental Code
Operar a nivel de bits (http://www.elguille.info/net/dotnet/operar_con_bits.aspx)
:P
.
Esta mal ese trato de flags...(Me dio un sape 79137913) esta bien la operacion de bits,
* Se igualan a los flags con los que se realizan las operaciones en algunos casos...
la suma no se hace como normalmente se hace... se hace de manera binaria...
0000 0000 0000 0001 = Battery charge status: High
0000 0000 0000 0010 = Battery charge status: Low
0000 0000 0000 0100 = Battery charge status: Critical
0000 0000 0000 1000 = Battery charge status: Charging
0000 0000 1000 0000 = Battery charge status: No system battery
0000 0000 1111 1111 = Battery charge status: Unknown Status
Operadores a nivel bit (https://secure.wikimedia.org/wikipedia/es/wiki/Operador_a_nivel_de_bits)
es decir que si te da 9 es decir
0000 0000 0000 1001 = 9
es por esto:
0000 0000 0000 0001 = Battery charge status: High
0000 0000 0000 1000 = Battery charge status: Charging
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 Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
Private Sub Form_Paint()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Hotmail.com
Dim SPS As SYSTEM_POWER_STATUS
'get the battery powerstatus
GetSystemPowerStatus SPS
Me.AutoRedraw = True
'show some information
Select Case SPS.ACLineStatus
Case 0
Me.Print "AC power status: Offline"
Case 1
Me.Print "AC power status: OnLine"
Case 2
Me.Print "AC power status: Unknown"
End Select
' Ya que se tratan de flags, se omiten los else a cada if ... then
If (SPS.BatteryFlag And &H1) = &H1 Then Me.Print "Battery charge status: High"
If (SPS.BatteryFlag And &H2) = &H2 Then Me.Print "Battery charge status: Low"
If (SPS.BatteryFlag And &H4) = &H4 Then Me.Print "Battery charge status: Critical"
If (SPS.BatteryFlag And &H8) = &H8 Then Me.Print "Battery charge status: Charging"
If (SPS.BatteryFlag And &H80) = &H80 Then Me.Print "Battery charge status: No system battery"
If (SPS.BatteryFlag And &HFF) = &HFF Then Me.Print "Battery charge status: Unknown Status"
End Sub
Dulces Lunas!¡.