www.pudn.com > QQShield.rar > Form1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
using System.IO;
using Microsoft.Win32;
namespace QQShield
{
///
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
[DllImport("user32.dll",SetLastError=true)]
public static extern bool RegisterHotKey( IntPtr hWnd,int id,
KeyModifiers fsModifiers,
Keys vk );// virtual-key code
[DllImport("user32.dll", SetLastError=true)]
public static extern bool UnregisterHotKey( IntPtr hWnd, // handle to window
int id // hot key identifier
);
[Flags()]
public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}
private bool _isMoving;
private int XOffset;
private int YOffset;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Timer timer2;
private System.Windows.Forms.Timer timer3;
private Form2 f=new Form2();
private bool isactive=true;
public static string password;
public Hashtable sn1,sn2;
private string PPP="xiaolai"; //**************************************************************************************
//private Service sv=new Service(300);
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.Visible=false;
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
protected override void WndProc( ref Message m )//overide该函数!!!!!
{
const int WM_HOTKEY = 0x0312; //设置热健!!
switch(m.Msg)
{
case WM_HOTKEY:
switch (m.WParam.ToInt32())
{
case 1001:
//MessageBox.Show("sfsfsfS");
OnHotKeyF9();
break;
case 1002:
//MessageBox.Show("sfsfsfS");
OnHotKeyF10();
break;
case 1003:
//MessageBox.Show("sfsfsfS");
OnHotKeyF11();
break;
default:break;
}
break;
}
base.WndProc(ref m );
}
private void OnHotKeyF11()
{
MessageBox.Show("要退出程序吗?");
PWD pwd=new PWD();
pwd.ShowDialog(this);
if(password!=PPP)
{
MessageBox.Show("密码错误");
}
else
{
MessageBox.Show("程序已退出!");
this.Close();
Application.Exit();
}
}
private void OnHotKeyF10()
{
}
private void OnHotKeyF9()//按热健后执行的函数
{
// MessageBox.Show("程序已退出!");
// this.Close();
// Application.Exit();
if(this.isactive)
{
MessageBox.Show("将要失去保护!确定吗?");
PWD pwd=new PWD();
pwd.ShowDialog(this);
if(password!=PPP)
{
MessageBox.Show("密码错误");
}
else
{
this.isactive=false;
MessageBox.Show("已失去保护");
}
}
else
{
this.isactive=true;
MessageBox.Show("已开始保护");
}
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.timer3 = new System.Windows.Forms.Timer(this.components);
//
// timer1
//
this.timer1.Interval = 2000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// timer2
//
this.timer2.Interval = 10;
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
//
// timer3
//
this.timer3.Interval = 1000;
this.timer3.Tick += new System.EventHandler(this.timer3_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(16, 11);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Opacity = 0;
this.Text = "不准斗地主!!!";
this.TopMost = true;
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
}
#endregion
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
bool cw;//实现程序的互斥运行!
Mutex m=new Mutex(true,"test9817677266277",out cw);
if(cw)
{
Application.Run(new Form1());
}
else
{
MessageBox.Show("程序已经运行啦");
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
//this.Size=new System.Drawing.Size(1, 3);
RegisterHotKey(Handle, 1001,KeyModifiers.Control,Keys.F9);//给f9分配ID为1001
RegisterHotKey(Handle, 1002,KeyModifiers.Control,Keys.F10);
RegisterHotKey(Handle, 1003,KeyModifiers.Control,Keys.F11);
GraphicsPath mygp2=new GraphicsPath();
mygp2.AddEllipse(0,0,this.Size.Width,this.Size.Height);
this.Region=new Region(mygp2);
autorun(true);
this.timer1.Start();
this.timer2.Start();
this.timer3.Start();
}
private void button1_Click(object sender, System.EventArgs e)
{
//this.WindowState=FormWindowState.Minimized;
this.Hide();
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ( e.Button == MouseButtons.Left )
{
// No need to check for transparency here, because the
// child controls are not on transparent areas.
_isMoving = true;
XOffset = e.X;
YOffset = e.Y;
}
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ( e.Button == MouseButtons.Left )
{
_isMoving = false;
}
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ( _isMoving )
{
Control c = sender as Control;
this.Location = new Point(this.Location.X + e.X - XOffset,
this.Location.Y + e.Y - YOffset );
}
}
//##########################################################################################################################################
private bool iscnt(int[,] a,int x,int y)
{
for(int i=0;i<200;i++)
{
if((a[i,0]==x)&&(a[i,1]==y))
{
return true;
}
}
return false;
}
private void autorun(bool run)//实现程序开机运行
{
string path=System.IO.Directory.GetCurrentDirectory()+"\\"+"svchost.exe";
RegistryKey rLocal = Registry.LocalMachine;
RegistryKey key1=null;
if(run==true)
{
try
{
key1 = rLocal.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);
key1.SetValue ("systemid",path);
key1.Close();
}
catch
{
}
if(key1 ==null)
{
try
{
RegistryKey key2=rLocal.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
key2.SetValue ("systemid",path);
key2.Close();
}
catch
{
}
}
}
else
{
try
{
key1 = rLocal.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);
key1.DeleteValue("systemid");
key1.Close();
}
catch
{
}
if(key1 ==null)
{
try
{
RegistryKey key2=rLocal.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
key2.DeleteValue("systemid");
key2.Close();
}
catch
{
}
}
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void timer1_Tick(object sender, System.EventArgs e)//是否有信息管理器在运行
{
if(this.isactive)
{
IntPtr hwc=MainC.FindWindows("信息管理器");
int xx=(int)hwc;
if(xx!=0)
{
MainC.CloseWindows(hwc);
f.Show();
}
// MainC.check();
}
}
private void timer2_Tick(object sender, System.EventArgs e)//用于开始时隐藏窗体
{
this.Hide();
this.timer2.Stop();
//this.ClientSize = new System.Drawing.Size(461, 343);
}
private void timer3_Tick(object sender, System.EventArgs e)//每隔一定时间重设开机自启动
{
// autorun(true);
// this.timer3.Interval=3600000;
if(this.isactive)
{
MainC.check();
}
}
}
}