Autor Tema: Apagar la pantalla pero sin suspender la Tableta (Resuelto)  (Leído 7355 veces)

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

antonio2005pe

  • Bytes
  • *
  • Mensajes: 49
  • Reputación: +0/-1
    • Ver Perfil
Apagar la pantalla pero sin suspender la Tableta (Resuelto)
« en: Julio 30, 2015, 02:55:01 am »
Hola Amigos, uso la api de windows para apagar la pantalla

Código: [Seleccionar]
Public Declare Function SendMessage _
    Lib "user32" _
    Alias "SendMessageA" ( _
        ByVal hwnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, lParam As Any) As Long

Const WM_SYSCOMMAND = &H112&
Const SC_MONITORPOWER = &HF170&
 

y lo llama asi para apagar la pantalla
Código: [Seleccionar]
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal 2&
tengo un formulario con un timer que hace un select al servidor y debe desbloquear el equipo si encuentra algun dato en el select, pero cuando se apaga la pantalla se bloquea el equipo y el formulario deja de funcionar, quiero apagar la pantalla para ahorrar energia, hay alguna forma de hacerlo?

Muchas Gracias.
« última modificación: Agosto 09, 2015, 04:53:50 pm por antonio2005pe »

79137913

  • Megabyte
  • ***
  • Mensajes: 185
  • Reputación: +21/-4
  • 4 Esquinas
    • Ver Perfil
    • Eco.Resumen Resumenes Cs. Economicas
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #1 en: Julio 30, 2015, 02:03:42 pm »
HOLA!!!

Mostra una pantalla blanca o negra segun tu tipo de display para ahorrar bateria del dispositivo:
http://www.smartblog.es/2011/07/como-ahorrar-bateria-en-tu-movil-fondos-de-pantalla/

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

antonio2005pe

  • Bytes
  • *
  • Mensajes: 49
  • Reputación: +0/-1
    • Ver Perfil
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #2 en: Julio 31, 2015, 03:09:34 am »
HOLA!!!

Mostra una pantalla blanca o negra segun tu tipo de display para ahorrar bateria del dispositivo:
http://www.smartblog.es/2011/07/como-ahorrar-bateria-en-tu-movil-fondos-de-pantalla/

GRACIAS POR LEER!!!
Muchas gracias por tu respuesta, pero no habria otra forma solo de apagar la pantalla pero no suspender la tablet?, me refiero que si alguien necesita escuchar musica por ejemplo en su tablet en la calle deberia poder apagar solo la pantalla sin que se le apage la musica o algun otro programa en background funcionando.

79137913

  • Megabyte
  • ***
  • Mensajes: 185
  • Reputación: +21/-4
  • 4 Esquinas
    • Ver Perfil
    • Eco.Resumen Resumenes Cs. Economicas
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #3 en: Julio 31, 2015, 09:08:53 am »
HOLA!!!

Yo creo que la tablet On_Wake va a pedir pass siempre que este configurada de esa manera, se puede quitar el bloqueo de pantalla, pero eso es desde la configuracion de windows no desde tu programa.

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

antonio2005pe

  • Bytes
  • *
  • Mensajes: 49
  • Reputación: +0/-1
    • Ver Perfil
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #4 en: Julio 31, 2015, 09:21:31 pm »
Muchas gracias, seguire buscando pera ver si encuentro alguna mejor solucion y si la encuentro la pongo aqui para los que tenga el mismo problema.

Albertomi

  • Gigabyte
  • ****
  • Mensajes: 281
  • Reputación: +153/-0
    • Ver Perfil
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #5 en: Agosto 01, 2015, 03:13:48 pm »
Estimado antonio2005pe
 
Agrega el siguiente código
En un Formulario
===============================================
Private Sub Form_Load()
  Timer1.Interval = 5000
End Sub

Private Sub Timer1_Timer()
  DoNotSleep
End Sub

===============================================
 
En un Modulo
===============================================
Private Enum Execution_State
  ES_SYSTEM_REQUIRED = &H1
  ES_DISPLAY_REQUIRED = &H2
  ES_USER_PRESENT = &H4
  ES_CONTINUOUS = &H80000000
End Enum
Private Declare Sub SetThreadExecutionState Lib "kernel32" (ByRef esFlags As Execution_State)

Private Const SPI_SETSCREENSAVETIMEOUT = 15
Private Declare Function SystemParametersInfo Lib "User" (ByVal uAction As Integer, ByVal uparam As Integer, lpvParam As Any, ByVal fuWinIni As Integer) As Integer


   
Public Sub DoNotSleep()
  'Sets the screen saver time-out value to the
  'value of the uiParam parameter. This value is the amount of time,
  'in seconds, that the system must remain idle before the screen saver activates.
  'So, if you set it 30, it will suspend the screensaver & Power Off features for 30 minutes
  SystemParametersInfo SPI_SETSCREENSAVETIMEOUT, 30, 0, 0
  SetThreadExecutionState ES_CONTINUOUS Or ES_DISPLAY_REQUIRED Or ES_CONTINUOUS
End Sub

===============================================
 
Está es otra alternativa, y consiste en que invoques un comando de PowerShell desde VB
powercfg -hibernate off
powercfg -hibernate on

 
Si requieres más información de PowerShell, te dejo estos link
  https://technet.microsoft.com/es-es/library/cc748940(v=ws.10).aspx
  http://www.techrepublic.com/article/investigate-windows-sleep-states-with-the-powercfg-command/
 
Saludos, desde algún lugar de Lima-Perú
Saludos, desde algún lugar de Lima-Perú

antonio2005pe

  • Bytes
  • *
  • Mensajes: 49
  • Reputación: +0/-1
    • Ver Perfil
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #6 en: Agosto 01, 2015, 08:02:05 pm »
Muchas Gracias, lo probare enseguida.

antonio2005pe

  • Bytes
  • *
  • Mensajes: 49
  • Reputación: +0/-1
    • Ver Perfil
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #7 en: Agosto 01, 2015, 08:07:58 pm »
Estimado antonio2005pe
 
Agrega el siguiente código
En un Formulario
===============================================
Private Sub Form_Load()
  Timer1.Interval = 5000
End Sub

Private Sub Timer1_Timer()
  DoNotSleep
End Sub

===============================================
 
En un Modulo
===============================================
Private Enum Execution_State
  ES_SYSTEM_REQUIRED = &H1
  ES_DISPLAY_REQUIRED = &H2
  ES_USER_PRESENT = &H4
  ES_CONTINUOUS = &H80000000
End Enum
Private Declare Sub SetThreadExecutionState Lib "kernel32" (ByRef esFlags As Execution_State)

Private Const SPI_SETSCREENSAVETIMEOUT = 15
Private Declare Function SystemParametersInfo Lib "User" (ByVal uAction As Integer, ByVal uparam As Integer, lpvParam As Any, ByVal fuWinIni As Integer) As Integer


   
Public Sub DoNotSleep()
  'Sets the screen saver time-out value to the
  'value of the uiParam parameter. This value is the amount of time,
  'in seconds, that the system must remain idle before the screen saver activates.
  'So, if you set it 30, it will suspend the screensaver & Power Off features for 30 minutes
  SystemParametersInfo SPI_SETSCREENSAVETIMEOUT, 30, 0, 0
  SetThreadExecutionState ES_CONTINUOUS Or ES_DISPLAY_REQUIRED Or ES_CONTINUOUS
End Sub

===============================================
 
Está es otra alternativa, y consiste en que invoques un comando de PowerShell desde VB
powercfg -hibernate off
powercfg -hibernate on

 
Si requieres más información de PowerShell, te dejo estos link
  https://technet.microsoft.com/es-es/library/cc748940(v=ws.10).aspx
  http://www.techrepublic.com/article/investigate-windows-sleep-states-with-the-powercfg-command/
 
Saludos, desde algún lugar de Lima-Perú
Estimado Albertomi, me sale un error en el Timer "Error 53 en tiempo de ejecucion, No se a encontrado el archivo: User"
Gracias.

Albertomi

  • Gigabyte
  • ****
  • Mensajes: 281
  • Reputación: +153/-0
    • Ver Perfil
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #8 en: Agosto 02, 2015, 02:10:34 am »
Estimado antonio2005pe
 
Reemplaza todo el código del modulo, por el siguiente código
===========================================
Option Explicit
Private Enum Execution_State
  ES_SYSTEM_REQUIRED = &H1
  ES_DISPLAY_REQUIRED = &H2
  ES_USER_PRESENT = &H4
  ES_CONTINUOUS = &H80000000
End Enum
Private Declare Sub SetThreadExecutionState Lib "kernel32" (ByRef esFlags As Execution_State)

Const SPI_SETSCREENSAVETIMEOUT = 15
Declare Function SystemParametersInfo Lib "user32.dll" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uiParam As Long, pvParam As Any, ByVal fWinIni As Long) As Long


   
Public Sub DoNotSleep()
  'Sets the screen saver time-out value to the
  'value of the uiParam parameter. This value is the amount of time,
  'in seconds, that the system must remain idle before the screen saver activates.
  'So, if you set it 30, it will suspend the screensaver & Power Off features for 30 minutes
  SystemParametersInfo SPI_SETSCREENSAVETIMEOUT, 30, 0, 0
  SetThreadExecutionState ES_CONTINUOUS Or ES_DISPLAY_REQUIRED Or ES_CONTINUOUS
End Sub

===========================================
 
Saludos, desde algún lugar de Lima-Perú
Saludos, desde algún lugar de Lima-Perú

antonio2005pe

  • Bytes
  • *
  • Mensajes: 49
  • Reputación: +0/-1
    • Ver Perfil
Re:Apagar la pantalla pero sin suspender la Tableta
« Respuesta #9 en: Agosto 09, 2015, 04:53:26 pm »
Muchas Gracias, me funciono de maravilla :).