'Turn screen off using C windows 8
I want to write a very tiny app using C that would turn the screen off or on. mapping keys to call a specific function should not be difficult.
Which are the system commands to turn the screen off or on on windows?
Thanks
Solution 1:[1]
// Turn off monitor
Sleep(500); // Eliminate user's interaction for 500 ms
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
// Turn on monitor
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) -1);
// Low power monitor
Sleep(500); // Eliminate user's interaction for 500 ms
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 1);
Note that
**1** - the display is going to low power.
**2** - the display is being shut off.
**-1** - the display is being turned on (undocumented value).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hana Bzh |
