this code should work, but i am not 100% sure i hav the sendmessage declared right. Can someone help me debug this?
It's a console program and if you pass it the parameter "off" it is supposed to turn the monitor off. It doesn't.
vb Code:
Module Module1 Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long Const HWND_BROADCAST As Integer = &HFFFF Const SC_MONITORPOWER As Integer = &HF170 Const WM_SYSCOMMAND As Short = &H112S Sub Main() Dim instr As String = Command() Select Case Command().ToLower 'Make sure it matches - and look at the commandline switch Case "off" TurnOff() Case "on" TurnOn() End Select End Sub Sub TurnOff() MsgBox("turning off") SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2) End Sub Sub TurnOn() SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1) End Sub End Module
If someone has a better solution for what i need it for, i am all ears. I am writing a custom program that launches with the remote power button on my media center remote. It is to turn the monitor off and on.
Advanced planned functionality includes muting the sound at the same time.




Reply With Quote