elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 08:56  


Tema destacado: Nueva página de elhacker.net en Google+ Google+

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo, raul338)
| | |-+  Problema con la API GetSystemPowerStatus
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problema con la API GetSystemPowerStatus  (Leído 638 veces)
Elemental Code


Desconectado Desconectado

Mensajes: 499


Im beyond the system


Ver Perfil
Problema con la API GetSystemPowerStatus
« en: 19 Agosto 2011, 18:19 »

HOLA!!! :D

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

Código
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 :)


En línea

79137913


Desconectado Desconectado

Mensajes: 780


4 Esquinas


Ver Perfil WWW
Re: Problema con la API GetSystemPowerStatus
« Respuesta #1 en: 19 Agosto 2011, 18:24 »

HOLA!!!

SO' BOLUDO' ?

XD

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


Pone asi y va a funcionar:
Código
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!!!


« Última modificación: 19 Agosto 2011, 18:28 por 79137913 » En línea

"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*                                                          Resumenes Cs.Economicas
Elemental Code


Desconectado Desconectado

Mensajes: 499


Im beyond the system


Ver Perfil
Re: Problema con la API GetSystemPowerStatus
« Respuesta #2 en: 20 Agosto 2011, 01:03 »

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

Gracias mi buen amigo :)

PD: como usaste el and? no entiendi :P
« Última modificación: 20 Agosto 2011, 01:08 por Elemental Code » En línea

raul338
Moderador
***
Desconectado Desconectado

Mensajes: 2.372


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: Problema con la API GetSystemPowerStatus
« Respuesta #3 en: 20 Agosto 2011, 01:13 »

@Elemental Code

Operar a nivel de bits

:P
En línea

BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.832


I'Love...!¡.


Ver Perfil WWW
Re: Problema con la API GetSystemPowerStatus
« Respuesta #4 en: 21 Agosto 2011, 06:41 »

.
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
 
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!¡.
« Última modificación: 21 Agosto 2011, 19:21 por BlackZeroX▓▓▒▒░░ » En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines