当我挂机下载的时候,往往习惯把显示器给关了。由于最近换了个显示器,新显示器的电源按钮比较小,按起来不大习惯,便想自己写个程序实现关闭显示器的功能。
代码很简单,用C#实现的。这里就不解释了,直接贴上来了,有同样需求的朋友可以参考一下。
代码
public static class MonitorControler
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
const int SC_MONITORPOWER = 0xF170;
const int WM_SYSCOMMAND = 0x0112;
enum MonitorMode : int
{
ON = -1,
STANBY = 1,
OFF = 2,
}
static void ChangeMonitorState(MonitorMode mode)
{
SendMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, (int)mode);
}
public static void Off()
{
ChangeMonitorState(MonitorMode.OFF);
}
public static void On()
{
ChangeMonitorState(MonitorMode.ON);
}
public static void StandBy()
{
ChangeMonitorState(MonitorMode.STANBY);
}
}
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
const int SC_MONITORPOWER = 0xF170;
const int WM_SYSCOMMAND = 0x0112;
enum MonitorMode : int
{
ON = -1,
STANBY = 1,
OFF = 2,
}
static void ChangeMonitorState(MonitorMode mode)
{
SendMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, (int)mode);
}
public static void Off()
{
ChangeMonitorState(MonitorMode.OFF);
}
public static void On()
{
ChangeMonitorState(MonitorMode.ON);
}
public static void StandBy()
{
ChangeMonitorState(MonitorMode.STANBY);
}
}