Skip to content

Instantly share code, notes, and snippets.

@jglozano
Created August 21, 2014 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jglozano/c0f3126c2e42537fe0e0 to your computer and use it in GitHub Desktop.
Save jglozano/c0f3126c2e42537fe0e0 to your computer and use it in GitHub Desktop.
Turn off displays
public static class Display {
private const uint WmSyscommand = 0x0112;
private const int ScMonitorpower = 0xF170;
private const int HwndBroadcast = 0xFFFF;
private const int ShutOffDisplay = 2;
[DllImport("user32.dll", SetLastError = true)]
private static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
public static void TurnOff() {
PostMessage((IntPtr)HwndBroadcast, WmSyscommand, (IntPtr)ScMonitorpower, (IntPtr)ShutOffDisplay);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment