By using the Windows API it is possible to put the monitors into sleep mode:
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
and then
SendMessage(this.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)2);
When running the command above, both monitors go to sleep. Is it possible to make this affect only one of multiple connected monitors?
When we use the Linux or UNIX operating system, we need to include “unistd.h” header file in our program to use the sleep () function. While using the Windows operating system, we have to include “Windows.h” header to use the sleep () function.
The time provided is mostly in milliseconds, microseconds or seconds and depending on that we have various functions that can put the program to sleep. C++ language does not provide a sleep function of its own.
Sleep () and usleep () functions are same except for the time unit used to specify the sleep time. In sleep () function, the time is specified in seconds, while in usleep () function, the time is specified in microseconds. The thread functions sleep_for () suspends the thread execution for a specific time period provided as an argument.
Q #2) What is the header file for sleep in C++? Answer: The header for sleep is “unistd.h” for LINUX/UNIX Operating system and “Windows.h” for the Windows Operating system. For thread sleep that uses ‘sleep_for’ and ‘sleep_until’ functions, <thread> header is used.
Exactly I don't know if you can put into sleep a specific monitor.. but you can achieve this by changing number of displays to One (assuming you have 2), which you want to be awake. The other one will automatically goes to sleep after about a minute (most monitors enter power save mode after about a minute after disconnect). You are essentially disconnecting the monitor, programatically. You can activate it when you need it.
However this method will have other implications, which you will know once you start playing with it.
According to this...no.
The reason being is that the API is turning off the display which is defined as both monitors. Turning off a specific monitor would be a hardware tie in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With