locked
Screen Power ON/OFF RRS feed

  • Question

  • I need to be able to power off and back on the screen from my program.

    Anyone know existing APIs to accomplish this?

      Ed

    Thursday, January 25, 2007 11:12 PM

Answers

  • This works:

    Public Class MonitorPower

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _

    (ByVal hWnd As IntPtr, ByVal wMsg As Integer, _

    ByVal wParam As Integer, ByVal lParam As Integer) As Integer

    Dim WM_SYSCOMMAND As Integer = &H112

    Dim SC_MONITORPOWER As Integer = &HF170

    Dim HWND_BROADCAST As Integer = &HFFFF

    Public Sub PowerOn()

    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1)

    End Sub

    Public Sub PowerOff()

    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)

    End Sub

    Public Sub PowerStandby()

    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 1)

    End Sub

    End Class

    Saturday, January 27, 2007 12:25 AM

All replies

  • Friday, January 26, 2007 3:11 PM
  • This looks like what I need.  I'll give it a try.

    Thanks,

       Ed

    Friday, January 26, 2007 10:23 PM
  • This works:

    Public Class MonitorPower

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _

    (ByVal hWnd As IntPtr, ByVal wMsg As Integer, _

    ByVal wParam As Integer, ByVal lParam As Integer) As Integer

    Dim WM_SYSCOMMAND As Integer = &H112

    Dim SC_MONITORPOWER As Integer = &HF170

    Dim HWND_BROADCAST As Integer = &HFFFF

    Public Sub PowerOn()

    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1)

    End Sub

    Public Sub PowerOff()

    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)

    End Sub

    Public Sub PowerStandby()

    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 1)

    End Sub

    End Class

    Saturday, January 27, 2007 12:25 AM