Results 1 to 4 of 4

Thread: Turn off monitor(s)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    20

    Turn off monitor(s)

    Hello

    Is there a way to click on a button and have your monitor turn off, like when your power settings are set to do so after a certain amount of time? Also, I want to be able to have the monitor come back on, but only after a specific key is pressed, not just on any key press or mouse movement.

    Thanks!
    Kosta

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here's the code in visual basic. Now you just have to port it over to vb.net

    Code:
    Option Explicit
    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
       
    Private Sub Command1_Click()
        ' Turn Monitor Off
        SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal -1&
    End Sub
    
    Private Sub Command2_Click()
        ' Turn monitor on
        SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal 0&
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    20
    Thanks for the help!

    Unfortunately, I'm new to both vb6 and vb.net. Do you have an example already in vb.net?

    Thanks again,
    Kosta

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    20
    I know this is an old post, but if anyone was interested:

    Code:
        Private Const WM_SYSCOMMAND = &H112
        Private Const SC_MONITORPOWER = &HF170
        Private Declare Ansi Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    
        Private Enum MonitorState
            StateOn = -1
            StateSuspend = 1
            StateOff = 2
        End Enum
    
        Private Sub SwitchMonitorState(ByVal State As MonitorState)
            SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, State)
        End Sub
    I just came across it...

    Thanks,
    Kosta

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