Turn off the monitor?

I have Windows 10 64 bit, and I spend a lot of time programming behind the screen. I need to break from time to time and limit the light / radiation of the screen from a collision with my head, making the screen black, as if turned off.

What I can do is go to the login screen, but I need to see BLACK for it to be released! What really hopes to achieve is a black screen that you get once inactive. Can I do this programmatically?

Here is the code I have had so far:

#include <Windows.h>

#define KEY_DOWN(key) ((::GetAsyncKeyState(key) & 0x80000) ? 1 : 0)
#define KEY_UP(key)   ((::GetAsyncKeyState(key) & 0x80000) ? 0 : 1)

int main(void)
{
    // Hide the console window
    HWND hWnd;
    AllocConsole();
    hWnd = FindWindowA("ConsoleWindowClass", NULL);
    ShowWindow(hWnd, 0);

    //Press ctrl + alt + 'L' to lock / Press ctrl + 'E' to terminate the program
    while (1)
    {
        if (::GetAsyncKeyState('L') == -32767)
        {
            if (KEY_DOWN(VK_CONTROL) && KEY_DOWN(VK_MENU))
                LockWorkStation();
        }
        if (::GetAsyncKeyState('E') == -32767)
        {
            if (KEY_DOWN(VK_CONTROL))
                return 0;
        }
    }
    return 0;
}
+4
source share
1 answer

Use the parameter SC_MONITORPOWERfor the message WM_SYSCOMMANDto turn off the monitor:

SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

2 .

. https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx

+5

All Articles