Jump to content

Dllcall does not work... partial


loady
 Share

Recommended Posts

Dear all,

I have a Windows 8 tablet hanging on the living room wall which is running permanently. There's also a precense detector in the living room, which communicates with a miniserver. If a person is in the room, it will be detected and the server triggers a programm. This is where my autoit script takes part.
If someone is in the room, a diashow (screensaver) should be shown. Otherwise, the screen should be turned off (for energie savings).

This works, so far. I can start the screensaver and I can turn off the monitor. But I cannot turn it on again. What am I doing wrong? Has anybody a clue?

According to MSDN, it should work like this: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx

settings.ini

Spoiler
[Netzwerk]
IP-Adresse=192.168.132.100
IP-Port=1989

 

constants.au3

Spoiler
Global Const $listen_IP         = IniRead("einstellungen.ini", "Netzwerk", "IP-Adresse", "127.0.0.1")
Global Const $listen_PORT       = IniRead("einstellungen.ini", "Netzwerk", "IP-Adresse", "1989")
Global Const $CMD_SCREENSAVER   = "cmd_bildschirmschoner"
Global Const $CMD_MONITOR_AN    = "cmd_monitor_an"
Global Const $CMD_MONITOR_AUS   = "cmd_monitor_aus"
;~ Global Const $CMD_MOUSE_MOVE = "cmd_mouse_move"

 

miniserver.au3

Spoiler
#include "constants.au3"
#include <Constants.au3>
#NoTrayIcon

TCPStartup()

Local $ID_socket = TCPConnect($listen_IP, $listen_PORT)

If $CmdLine[0] >= 1 Then
   Switch $CmdLine[1]
   Case "-bildschirmschoner"
      TCPSend($ID_socket, $CMD_SCREENSAVER)
   Case "-an"
      TCPSend($ID_socket, $CMD_MONITOR_AN)
   Case "-aus"
      TCPSend($ID_socket, $CMD_MONITOR_AUS)
   Case Else
      MsgBox(0,"Fehler", $CmdLine[1] & " ist kein gültiger Paramter")
   EndSwitch
Else
   MsgBox(0,"Fehler", "Parameter wird zwingend gebraucht" & @CRLF & @CRLF & "Bsp.:" & @CRLF & "miniserver.exe -bildschirmschoner" & @CRLF & "miniserver.exe -an" & @CRLF & "miniserver.exe -aus")
EndIf

TCPCloseSocket($ID_socket)

 

tablet.au3

Spoiler
#include "constants.au3"
#NoTrayIcon

TCPStartup()

Local $ID_socket = TCPListen($listen_IP, $listen_PORT, 100)

While True
   Local $socket_established = -1
   Local $socket_received_data = Null

   Do
      $socket_established = TCPAccept($ID_socket)
      Sleep(100)
   Until $socket_established <> -1

   $socket_received_data = TCPRecv($socket_established, 1024)
   TCPCloseSocket($socket_established)

   _do($socket_received_data)
WEnd

Func _do($TCP_DATA)
   Switch $TCP_DATA
   Case $CMD_SCREENSAVER
      Local $result = DllCall("user32.dll", "hwnd", "GetDesktopWindow")
      DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $result[0], "uint", 0x0112, "wparam", 0xF140, "lparam", 0)
   Case $CMD_MONITOR_AN
      DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', WinGetHandle('[CLASS:Progman]'), 'int', 0x0112, 'int', 0xF170, 'int', -1)
   Case $CMD_MONITOR_AUS
      DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', WinGetHandle('[CLASS:Progman]'), 'int', 0x0112, 'int', 0xF170, 'int', 2)
   EndSwitch
EndFunc

;~ https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx

 

Thank you in advance

Link to comment
Share on other sites

Weird, they both work fine for me on Windows 7. Is it an Windows 8 or Windows 10 tablet? You could try using 1 instead of 2 for the last argument to the DLLCall to put the monitor to sleep. It doesn't work on my machine but it may work on yours. 1 is sleep mode instead of power off.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...