-1

I want, that the monitor will turn off, and after a certain period of time it will turn on. But the monitor doesn't want to turn on. What is wrong i do?

HWND hwnd_monitor = FindWindow(0, 0);
SendMessage(hwnd_monitor, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
Sleep(1000);
SendMessage(hwnd_monitor, WM_SYSCOMMAND, SC_MONITORPOWER, -1);
  • 5
    Possible duplicate of [SendMessage/SC\_MONITORPOWER won't turn monitor ON when running Windows 8](https://stackoverflow.com/questions/12572441/sendmessage-sc-monitorpower-wont-turn-monitor-on-when-running-windows-8) – Nelfeal Dec 03 '18 at 11:48
  • 1
    @Philipp `hwnd_monitor` is window handle (`HWND`), not "monitor handle", so it's unclear why that should become invalid. – Algirdas Preidžius Dec 03 '18 at 11:50

1 Answers1

-4

You can try to move the mouse and that will wake the monitor back on. Here's a solution provided at the link : http://stackoverflow.com/questions/12572441/sendmessage-sc-monitorpower-wont-turn-monitor-on-when-running-windows-8

[DllImport("user32.dll")]
static extern void mouse_event(Int32 dwFlags, Int32 dx, Int32 dy, Int32 dwData, UIntPtr dwExtraInfo);

private const int MOUSEEVENTF_MOVE = 0x0001;

private void Wake(){
    mouse_event(MOUSEEVENTF_MOVE, 0, 1, 0, UIntPtr.Zero);
    Sleep(40);
    mouse_event(MOUSEEVENTF_MOVE, 0, -1, 0, UIntPtr.Zero);
}
ohl13
  • 11
  • 5