用C#编写关显示器软件
大家可能用过各种各样的关机软件,但是有没有想过去写一个关闭屏幕的程序呢?在C#大行其道的今天,用c#来编写一个自己的关屏软件呢,方便自己整蛊他人也许是个很好的方法呢呢~~今天Xushine研究院就来给大家介绍下~因为代码过于简单,就不在这里写注释了~不懂可以提问~
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ControlHardWare
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region SendMessage
public const uint WM_SYSCOMMAND = 0×0112;
public const uint SC_MONITORPOWER = 0xF170;
[DllImport("user32")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, uint wParam, int lParam);
#endregion
private void button1_Click(object sender, EventArgs e)
{
CloseLCD(sender, e);
}
void CloseLCD(object sender, EventArgs e)
{
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2); // 2 为关闭显示器, -1则打开显示器
}
}
}
评论被关闭。