给你个源码参考一下,这个是模拟死机的程序,和你的锁屏功能差不多,开了个线程扼杀了任务管理器和win+R打开的运行窗口。输入"abcd"解锁,如果输入错误可以按回车重新输入
public partial class Form1 : Form
{
Thread thread;
string str = "";
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, int msg, int wparam, int iparam);
[DllImport("gdi32.dll")]
private static extern IntPtr CreateDC(
string lpszDriver, // 驱动名称
string lpszDevice, // 设备名称
string lpszOutput, // 无用,可以设定位"NULL"
IntPtr lpInitData // 任意的打印机数据
);
[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, //目标设备的句柄
int nXDest, // 目标对象的左上角的X坐标
int nYDest, // 目标对象的左上角的X坐标
int nWidth, // 目标对象的矩形的宽度
int nHeight, // 目标对象的矩形的长度
IntPtr hdcSrc, // 源设备的句柄
int nXSrc, // 源对象的左上角的X坐标
int nYSrc, // 源对象的左上角的X坐标
System.Int32 dwRop // 光栅的操作值
);
private void KillTaskmgr()
{
var processinfo = Process.GetProcesses();
foreach (var pro in processinfo)
{
if (pro.ProcessName == "taskmgr" || pro.ProcessName == "cmd")
{
try
{
pro.Kill();
}
catch { }
}
}
IntPtr ip = FindWindow(null, "运行");
if (ip != IntPtr.Zero)
{
SendMessage(ip, 0x10, 0, 0);
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.ShowInTaskbar = false;
thread = new Thread(KillTaskmgr);
thread.Start();
WindowState = FormWindowState.Maximized;
this.Visible = false;
IntPtr p1 = CreateDC(Screen.AllScreens[0].DeviceName, null, null, IntPtr.Zero);
Graphics g1 = Graphics.FromHdc(p1);
Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1);
Graphics g2 = Graphics.FromImage(bmp);
IntPtr p2 = g2.GetHdc();
IntPtr p3 = g1.GetHdc();
BitBlt(Graphics.FromImage(bmp).GetHdc(), 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, p3, 0, 0, 13369376);
g1.ReleaseHdc(p3);
g2.ReleaseHdc(p2);
BackgroundImage = bmp;
this.Visible = true;
}
protected override CreateParams CreateParams
{
get
{
const int CS_NOCLOSE = 0x200;
CreateParams cp = base.CreateParams;
cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE;
return cp;
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
str = "";
else
str += e.KeyCode.ToString();
if (str.ToLower().Trim() == "abcd")
{
if (thread.ThreadState == System.Threading.ThreadState.Running)
try
{
thread.Abort();
}
catch
{
;
}
this.Close();
}
}
}