首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

屏幕锁定程序有异常请各位修改

2012-08-10 
屏幕锁定程序有错误请各位修改Bitmap bp new Bitmap(@ + url) 异常安装钩子时 创建线程钩子 hHookSe

屏幕锁定程序有错误请各位修改
Bitmap bp = new Bitmap(@"" + url); 异常
安装钩子时 创建线程钩子 hHook=SetWindowsHookEx(,,,)里面的参数[怎么写都有错误.

C# code
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;using System.IO;using System.Reflection;namespace LockScreen{    public partial class frmLockScreen : Form    {        public frmLockScreen()        {            InitializeComponent();        }        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=Win32API.GetPrivateProfileString(Section,Key,"",temp,255,FilePath);            return temp.ToString();        }#region        public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);         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(frmLockScreen.KeyBoardHookProc);                hHook = Win32API.SetWindowsHookEx(WH_KEYBOARD, KeyBoardProcedure, Win32API.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);                if(hHook==0)                {                    HookClear();                }            }        }        public void HookClear()        {            bool rsetKeyboard=true;            if(hHook!=0)            {                rsetKeyboard=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(kbh.vkCode==(int)Keys.F4&&(int)Control.ModifierKeys==(int)Keys.Alt)                {                    return 1;                }                if(kbh.vkCode==(int)Keys.Tab&&(int)Control.ModifierKeys==(int)Keys.Alt)                {                    return 1;                }             }               return Win32API.CallNextHookEx(hHook,nCode,wParam,lParam);        }        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[i].ToString();            }            return password;        }               private void frmLockScreen_Load(object sender, EventArgs e)        {             HookStart();            pwd=IniReadValue("config","password",filePath);            string Image_url=IniReadValue("config","password",filePath);            if(File.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);            Win32API.ClipCursor(out rect);            int width=this.Width;            int height=this.Height;            label3.Location=new Point(width/2-80,height-height/5);        }        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)        {            label3.Text = DateTime.Now.ToString();        }                private void KillTaskmgr_Tick(object sender, EventArgs e)        {            Process[] remoteAll = Process.GetProcessesByName("taskmgr");            foreach (Process s in remoteAll)             {                s.Kill();            }        }    }}#endregion 



[解决办法]
http://www.codeproject.com/KB/dotnet/HookingInMicrosoftDotNET.aspx


http://www.codeproject.com/search.aspx?q=C%23+Hook+api&sbo=kw

热点排行