C#控制显示器开启和关闭

使用WindowsAPI实现该功能,代码如下:

public const uint WM_SYSCOMMAND = 0x0112;
public const uint SC_MONITORPOWER = 0xF170;
[DllImport("user32")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, uint wParam, int lParam);

void CloseLCD(object sender, EventArgs e)
{
    SendMessage(this.Handle, WM_SYSCOMMAND, 
    SC_MONITORPOWER, 2); // 2 为关闭显示器, -1则打开显示器
}

 

转载于:https://www.cnblogs.com/masahiro/archive/2011/07/06/10131177.html

你可能感兴趣的:(C#控制显示器开启和关闭)