elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  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 2,106 veces)
Elemental Code


Desconectado Desconectado

Mensajes: 622


Im beyond the system


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

HOLA!!! :D

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

Código
  1. Private Type SYSTEM_POWER_STATUS
  2.        ACLineStatus As Byte
  3.        BatteryFlag As Byte
  4.        BatteryLifePercent As Byte
  5.        Reserved1 As Byte
  6.        BatteryLifeTime As Long
  7.        BatteryFullLifeTime As Long
  8. End Type
  9. Private Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
  10. Private Sub Form_Paint()
  11.    'KPD-Team 2000
  12.    'URL: http://www.allapi.net/
  13.    'E-Mail: KPDTeam@Hotmail.com
  14.    Dim SPS As SYSTEM_POWER_STATUS
  15.    'get the battery powerstatus
  16.    GetSystemPowerStatus SPS
  17.    Me.AutoRedraw = True
  18.    'show some information
  19.    Select Case SPS.ACLineStatus
  20.        Case 0
  21.            Me.Print "AC power status: Offline"
  22.        Case 1
  23.            Me.Print "AC power status: OnLine"
  24.        Case 2
  25.            Me.Print "AC power status: Unknown"
  26.    End Select
  27.    Select Case SPS.BatteryFlag
  28.        Case 1
  29.            Me.Print "Battery charge status: High"
  30.        Case 2
  31.            Me.Print "Battery charge status: Low"
  32.        Case 4
  33.            Me.Print "Battery charge status: Critical"
  34.        Case 8
  35.            Me.Print "Battery charge status: Charging"
  36.        Case 128
  37.            Me.Print "Battery charge status: No system battery"
  38.        Case 255
  39.            Me.Print "Battery charge status: Unknown Status"
  40.    End Select
  41. End Sub
  42.  

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

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

Mis programas
79137913


Desconectado Desconectado

Mensajes: 1.169


4 Esquinas


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

HOLA!!!

SO' BOLUDO' ?

XD

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


Pone asi y va a funcionar:
Código
  1. Private Type SYSTEM_POWER_STATUS
  2.        ACLineStatus As Byte
  3.        BatteryFlag As Byte
  4.        BatteryLifePercent As Byte
  5.        Reserved1 As Byte
  6.        BatteryLifeTime As Long
  7.        BatteryFullLifeTime As Long
  8. End Type
  9. Private Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
  10. Private Sub Form_Paint()
  11.    'KPD-Team 2000
  12.    'URL: http://www.allapi.net/
  13.    'E-Mail: KPDTeam@Hotmail.com
  14.    Dim SPS As SYSTEM_POWER_STATUS
  15.    'get the battery powerstatus
  16.    GetSystemPowerStatus SPS
  17.    Me.AutoRedraw = True
  18.    'show some information
  19.    Select Case SPS.ACLineStatus
  20.        Case 0
  21.            Me.Print "AC power status: Offline"
  22.        Case 1
  23.            Me.Print "AC power status: OnLine"
  24.        Case 2
  25.            Me.Print "AC power status: Unknown"
  26.    End Select
  27.    If SPS.BatteryFlag And 1 Then Me.Print "Battery charge status: High"
  28.    If SPS.BatteryFlag And 2 Then Me.Print "Battery charge status: Low"
  29.    If SPS.BatteryFlag And 4 Then Me.Print "Battery charge status: Critical"
  30.    If SPS.BatteryFlag And 8 Then Me.Print "Battery charge status: Charging"
  31.    If SPS.BatteryFlag And 128 Then Me.Print "Battery charge status: No system battery"
  32.    If SPS.BatteryFlag And 255 Then Me.Print "Battery charge status: Unknown Status"
  33. End Sub

GRACIAS POR LEER!!!


« Última modificación: 19 Agosto 2011, 18:28 pm 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*
Elemental Code


Desconectado Desconectado

Mensajes: 622


Im beyond the system


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

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 am por Elemental Code » En línea

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

Mis programas
raul338


Desconectado Desconectado

Mensajes: 2.633


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 am »

@Elemental Code

Operar a nivel de bits

:P
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


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

.
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
  1.  
  2. Private Type SYSTEM_POWER_STATUS
  3.        ACLineStatus As Byte
  4.        BatteryFlag As Byte
  5.        BatteryLifePercent As Byte
  6.        Reserved1 As Byte
  7.        BatteryLifeTime As Long
  8.        BatteryFullLifeTime As Long
  9. End Type
  10. Private Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
  11. Private Sub Form_Paint()
  12.    'KPD-Team 2000
  13.    'URL: http://www.allapi.net/
  14.    'E-Mail: KPDTeam@Hotmail.com
  15.    Dim SPS As SYSTEM_POWER_STATUS
  16.    'get the battery powerstatus
  17.    GetSystemPowerStatus SPS
  18.    Me.AutoRedraw = True
  19.    'show some information
  20.    Select Case SPS.ACLineStatus
  21.        Case 0
  22.            Me.Print "AC power status: Offline"
  23.        Case 1
  24.            Me.Print "AC power status: OnLine"
  25.        Case 2
  26.            Me.Print "AC power status: Unknown"
  27.    End Select
  28.  
  29.    ' Ya que se tratan de flags, se omiten los else a cada if ... then
  30.    If (SPS.BatteryFlag And &H1) = &H1 Then Me.Print "Battery charge status: High"
  31.    If (SPS.BatteryFlag And &H2) = &H2 Then Me.Print "Battery charge status: Low"
  32.    If (SPS.BatteryFlag And &H4) = &H4 Then Me.Print "Battery charge status: Critical"
  33.    If (SPS.BatteryFlag And &H8) = &H8 Then Me.Print "Battery charge status: Charging"
  34.    If (SPS.BatteryFlag And &H80) = &H80 Then Me.Print "Battery charge status: No system battery"
  35.    If (SPS.BatteryFlag And &HFF) = &HFF Then Me.Print "Battery charge status: Unknown Status"
  36. End Sub
  37.  
  38.  

Dulces Lunas!¡.
« Última modificación: 21 Agosto 2011, 19:21 pm por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problema BlueZScanner y problema de conexión
Hacking Mobile
Kasswed 3 6,314 Último mensaje 6 Mayo 2006, 22:04 pm
por Gospel
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines