Results 1 to 7 of 7

Thread: [RESOLVED] trying to turn off monitor using sendmessage

Threaded View

  1. #1

    Thread Starter
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Resolved [RESOLVED] trying to turn off monitor using sendmessage

    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:
    1. Module Module1
    2.     Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    3.     (ByVal hwnd As Long, ByVal wMsg As Long, _
    4.      ByVal wParam As Long, ByVal lParam As Long) As Long
    5.     Const HWND_BROADCAST As Integer = &HFFFF
    6.     Const SC_MONITORPOWER As Integer = &HF170
    7.     Const WM_SYSCOMMAND As Short = &H112S
    8.  
    9.     Sub Main()
    10.         Dim instr As String = Command()
    11.         Select Case Command().ToLower
    12.             'Make sure it matches - and look at the commandline switch
    13.             Case "off"
    14.                 TurnOff()
    15.             Case "on"
    16.                 TurnOn()
    17.         End Select
    18.     End Sub
    19.  
    20.     Sub TurnOff()
    21.         MsgBox("turning off")
    22.  
    23.         SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)
    24.     End Sub
    25.  
    26.     Sub TurnOn()
    27.         SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1)
    28.     End Sub
    29.  
    30.  
    31. 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.
    Last edited by Lord Orwell; Dec 21st, 2008 at 10:56 AM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width