using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Diagnostics;
namespace LockScreen2
{
public partial class frmLockScreen : Form
{
public frmLockScreen()
{
InitializeComponent();
}
public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
private string filePath = Application.StartupPath + @"\config.ini";
private string pwd;
private int i = 0;
public string IniReadValue(string Section, string Key, string FilePath)
{
StringBuilder temp = new StringBuilder(255);
int i = LockScreen.Win32API.GetPrivateProfileString(Section, Key, "", temp, 255, FilePath);
return temp.ToString();
}
#region
HookProc KeyBoardProcedure;
static int hHook = 0;
public const int WH_KEYBOARD = 13;
public struct KeyBoardHookStruct
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
public void HookStart()
{
if (hHook == 0)
{
KeyBoardProcedure = new HookProc(this.KeyBoardHookProc );
hHook = LockScreen.Win32API.SetWindowsHookEx(WH_KEYBOARD, KeyBoardProcedure, LockScreen.Win32API.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
//hHook = LockScreen.Win32API.SetWindowsHookEx(2, KeyboardHookProcedure, IntPtr.Zero,
// GetCurrentThreadId());
if (hHook == 0)
{
HookClear();
}
}
}
public void HookClear()
{
bool rsetKeyboard = true;
if (hHook != 0)
{
rsetKeyboard = LockScreen.Win32API.UnHookWindowsHookEx(hHook);
hHook = 0;
}
if (!rsetKeyboard)
{
throw new Exception("取消钩子失败!");
}
}
public static int KeyBoardHookProc(int nCode, int wParam, IntPtr lParam)
{
if (nCode >= 0)
{
KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));
if (kbh.vkCode == 91)
{
return 1;
}
if (kbh.vkCode == 92)
{
return 1;
}
if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control)
{
return 1;
}
//if()
}
return LockScreen.Win32API.CallNextHookEx(hHook, nCode, wParam, lParam);
}
#endregion
/// <summary>
/// MD5 加密函数
/// </summary>
/// <param name="PWD">待加密的字符</param>
/// <param name="e"></param>
public static string MD5_str(string PWD)
{
MD5 md5 = MD5.Create();
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(PWD));
string password = "";
for (int i = 0; i < s.Length; i++)
{
password += s.ToString();
}
return password;
}
private void frmLockScreen_Load(object sender, EventArgs e)
{
HookStart();
pwd = IniReadValue("config", "password", filePath);
string Image_url = IniReadValue("config", "url", filePath);
if ( Exists(Image_url))
{
Bitmap bp = new Bitmap(@"" + Image_url);
this.BackgroundImage = bp;
}
else
{
string url = Application.StartupPath + "\\default.jpg";
Bitmap bp = new Bitmap(@"" + url);
this.BackgroundImage = bp;
}
Rectangle rect = new Rectangle(pictureBox1.Left, pictureBox1.Top, pictureBox1.Width + pictureBox1.Left, pictureBox1.Height + pictureBox1.Top);
LockScreen.Win32API.ClipCursor(out rect);
int width = this.Width;
int height = this.Height;
label2.Location = new Point(width / 2 - 80, height - height / 5);
}
private bool Exists(string Image_url)
{
throw new NotImplementedException();
}
private void ControlOpacity_Tick(object sender, EventArgs e)
{
if (this.Opacity <= 0.1)
{
this.Close();
}
else
{
this.Opacity = this.Opacity - 0.1;
}
}
private void showTime_Tick(object sender, EventArgs e)
{
label2.Text = DateTime.Now.ToString();
}
private void KillTaskmgr_Tick(object sender, EventArgs e)
{
Process[] remoteAll = Process.GetProcessesByName("taskmgr");
foreach (Process s in remoteAll)
{
s.Kill();
}
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
|