public MainForm() { InitializeComponent(); // 创建文件夹 System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mouseMonitor\\ string logFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mouseMonitor"; if (!System.IO.Directory.Exists(logFolder)) { System.IO.Directory.CreateDirectory(logFolder); } // 启动监控服务 mouseMonitor = new MouseMonitor(); state = new MouseState(); this.formStartHook(); // 启动另外一个记录线程,每分钟记录一次 this.saveThread = new Thread(new ThreadStart(BeginSave)); this.saveThread.IsBackground = true; this.saveThread.Start(); // 需要读取今天的点击次数 this.state.loadClick(DateTime.Today); // 获取最新版本信息 string url = "http://mousemonitor.funaio.com/upgrade/info"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); byte[] data = new byte[100]; receiveStream.Read(data, 0, 100); receiveStream.Close(); string newestVersion = Encoding.UTF8.GetString(data); newestVersion = newestVersion.Trim('\0'); if (newestVersion != CurrentVersion) { string message = "请到 http://mousemonitor.funaio.com/ 下载最新版本" + newestVersion; MessageBox.Show(message); } }
public static extern int SetWindowsHookEx(int idHook, MouseMonitor.MouseProc lpfn, IntPtr hInstance, int threadId);