Problema con la API GetSystemPowerStatus

Iniciado por Elemental Code, 19 Agosto 2011, 18:19 PM

0 Miembros y 1 Visitante están viendo este tema.

Elemental Code

HOLA!!! :D

Les dejo el codigo de la api segun la apiguide 3.7:

Código (vb) [Seleccionar]
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 :)

I CODE FOR $$$
Programo por $$$
Hago tareas, trabajos para la facultad, lo que sea en VB6.0

Mis programas

79137913

#1
HOLA!!!

SO' BOLUDO' ?

XD

8 de bateria cargando
+
1 de bateria con carga alta
=
9


Pone asi y va a funcionar:
Código (vb) [Seleccionar]
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!!!
"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

79137913                          *Shadow Scouts Team*

Elemental Code

#2
y como iba a saber yo que se sumaban?  :P

Gracias mi buen amigo :)

PD: como usaste el and? no entiendi :P

I CODE FOR $$$
Programo por $$$
Hago tareas, trabajos para la facultad, lo que sea en VB6.0

Mis programas

raul338


BlackZeroX

#4
.
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

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

Código (vb) [Seleccionar]


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!¡.
The Dark Shadow is my passion.