Jump to content

Turn off/on monitor ?


Recommended Posts

Hi

I have found a code snippet from VB turning off/on the monitor.

But I can't figure out to translate it in an correct dll call.

Here ist the VB Code:

Private 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&

'turn off
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal 2&

'turn on
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal -1&

I tried this in autoit ....

(of course not working)

$WM_SYSCOMMAND = '&H112&'
$SC_MONITORPOWER = '&HF170&'


; turn off
dllcall('user32','int','SendmessageA','long',$WM_SYSCOMMAND,'int', $SC_MONITORPOWER, 2)

sleep(10000)

; turn on 
dllcall('user32','int','SendmessageA','long',$WM_SYSCOMMAND,'int', $SC_MONITORPOWER, -1)

has anybody experiences with?

greetings mozart90

Link to comment
Share on other sites

i found it in this forum :)

;MsgBox(0, "Started", @ScriptName & " has started.... F11 = Monitor off, F10 = Monitor on, Esc = Exit Program.")
#NoTrayIcon

Opt("TrayMenuMode",1) 
Opt ("WinTitleMatchMode", 4)
HotKeySet("{F11}", "MonOff")
HotKeySet("{F10}", "MonOn")
HotKeySet("{Esc}", "Close")
While 1
    Sleep(0x7fffffff)
WEnd
Func Close()
    $hwnd = WinGetHandle('classname=Progman')
    DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1)   
    MsgBox(0, "Closing...", "Closing program.....")
    Exit
EndFunc;==>Close
Func MonOn()
    $hwnd = WinGetHandle('classname=Progman')
    DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1)
EndFunc;==>MonOn
Func MonOff()
    $hwnd = WinGetHandle('classname=Progman')
    Sleep(500)
    DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', 2)
EndFunc;==>MonOff
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...