-2

We are trying to turn the monitor off via code and turn it back on via code. We found code that works however it uses user32.dll and does not seem to work in 64 bit mode like the rest of our software (yes i did try the obvious user64.dll) Any suggestions?

'''

Public WM_SYSCOMMAND As Integer = &H112
Public SC_MONITORPOWER As Integer = &HF170
Private mainWindowHandle As IntPtr

Public Sub New(mainWindowHandle As IntPtr)
    InitializeComponent()
    Me.mainWindowHandle = mainWindowHandle
End Sub

<DllImport("user32.dll")>
Private Shared Function SendMessage(hWnd As Integer, hMsg As Integer, wParam As Integer, lParam As Integer) As Integer
End Function

Private Sub PowerOffButton_Click(sender As Object, e As RoutedEventArgs)
    SendMessage(mainWindowHandle, WM_SYSCOMMAND, SC_MONITORPOWER, 2)
End Sub

'''

  • Ok resolved it 5 min after posting. Turns out the mainWindowHandle we used was Process.GetCurrentProcess().Handle, that didn't work but Process.GetCurrentProcess().MainWindowHandle did. – Brett Claycomb Oct 11 '19 at 20:45

1 Answers1

-1

Original poster here, we were testing with Process.GetCurrentProcess().Handle once we swapped it to Process.GetCurrentProcess().MainWindowHandle it worked fine.