C# 自动关闭或打开显示器
C# 自动关闭或打开显示器
测试:
C# Code:
/// <summary>
/// 监视器开关控制
/// </summary>
public class MonitorTool
{
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(
IntPtr hWnd,
uint msg,
uint wParam,
int lParam);
//系统消息
private const uint WM_SYSCOMMAND = 0x112;
//关闭显示器的系统命令
private const int SC_MONITORPOWER = 0xF170;
//2为PowerOff, 1为省电状态,-1为开机
private const int MonitorPowerOff = 2;
/// <summary>
/// 关闭显示器
/// </summary>
public static void PowerOff(IntPtr hWnd)
{
SendMessage(
hWnd,
WM_SYSCOMMAND,
SC_MONITORPOWER,
2
);
}
/// <summary>
/// 打开显示器
/// </summary>
public static void PowerOn(IntPtr hWnd)
{
SendMessage(
hWnd,
WM_SYSCOMMAND,
SC_MONITORPOWER,
-1
);
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
/// <summary>
/// 监视器开关控制
/// </summary>
public class MonitorTool
{
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(
IntPtr hWnd,
uint msg,
uint wParam,
int lParam);
//系统消息
private const uint WM_SYSCOMMAND = 0x112;
//关闭显示器的系统命令
private const int SC_MONITORPOWER = 0xF170;
//2为PowerOff, 1为省电状态,-1为开机
private const int MonitorPowerOff = 2;
/// <summary>
/// 关闭显示器
/// </summary>
public static void PowerOff(IntPtr hWnd)
{
SendMessage(
hWnd,
WM_SYSCOMMAND,
SC_MONITORPOWER,
2
);
}
/// <summary>
/// 打开显示器
/// </summary>
public static void PowerOn(IntPtr hWnd)
{
SendMessage(
hWnd,
WM_SYSCOMMAND,
SC_MONITORPOWER,
-1
);
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
测试:
C# Code:
private void button2_Click(object sender, EventArgs e)
{
MonitorTool.PowerOff(this.Handle);
Thread.Sleep(3000);//三秒后自动打开显示器
MonitorTool.PowerOn(this.Handle);
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
private void button2_Click(object sender, EventArgs e)
{
MonitorTool.PowerOff(this.Handle);
Thread.Sleep(3000);//三秒后自动打开显示器
MonitorTool.PowerOn(this.Handle);
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网