tsunami

log in
history

MonitorOff

Luke Breuer
2009-02-12 01:33 UTC

introduction
MonitorOff is a little C program I wrote to bring my LCDs to standby and optionally lock the workstation. With the help of a program that lets me create hotkeys with the Windows key, I can now press Windows key-O to turn my LCDs off.

download
code
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>


WINUSERAPI
BOOL
WINAPI
LockWorkStation(
    VOID);


// The sleeping is due to Windows apparently processing monitor-waking
// events for a few hundred ms after the executable is launched by
// keyboard or mouse input.  I want immediate feedback of the display
// turning off and the below does it quite well (although there can
// be a bit of flickering).
int main()
{
    Sleep(100);

    SendMessage(GetForegroundWindow(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);

    Sleep(300);

    SendMessage(GetForegroundWindow(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);

    Sleep(1000);

    SendMessage(GetForegroundWindow(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);

    //LockWorkStation();

    return 0;
}