2014-11-16

Turn your monitor off in C#

I want make a program for workers who always see a monitor.

To do that, I found a csharp source to turn off a monitor on windows.

But couldn't be used at a time, so I changed a little bit to use it easily.

using System.Runtime.InteropServices;
static class Program
{
    public static void Main()
    {
        SendMessage(0xFFFF, 0x112, 0xF170, (int)MonitorState.MonitorStateOff);
    }

    [DllImport("user32.dll")]
    private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);

    public enum MonitorState
    {
        MonitorStateOn = -1,
        MonitorStateOff = 2,
        MonitorStateStandBy = 1
    }
}

The original source is here : turn-monitor-c

No comments:

Post a Comment