/// <summary> /// 刷新边框 /// </summary> private void RefreshRect() { Rectangle reBarRC = new Rectangle(); Rectangle msTaskSwRC = new Rectangle(); WindowApi.GetWindowRect(msTaskSwInPtr, ref msTaskSwRC); WindowApi.GetWindowRect(reBarInPtr, ref reBarRC); if (this.reBarRC != reBarRC || this.msTaskSwRC != msTaskSwRC) { this.reBarRC = reBarRC; this.msTaskSwRC = msTaskSwRC; if (this.msTaskSwRC.Right - this.msTaskSwRC.Left > this.reBarRC.Botton - this.reBarRC.Top) { WindowApi.MoveWindow(this.handle, (IntPtr)(this.msTaskSwRC.Right - this.msTaskSwRC.Left - this.Width + 2), (IntPtr)((this.reBarRC.Botton - this.reBarRC.Top - this.Height) / 2), (int)this.Width, (int)this.Height, 1); } else { WindowApi.MoveWindow(this.handle, (IntPtr)((this.msTaskSwRC.Right - this.msTaskSwRC.Left - this.Width) / 2), (IntPtr)(this.reBarRC.Botton - this.reBarRC.Top - this.Height + 2), (int)this.Width, (int)this.Height, 1); } } }
/// <summary> /// 窗体加载事件 /// </summary> /// <param name="sender">发送者</param> /// <param name="e">信息</param> private void WindowLoad(object sender, RoutedEventArgs e) { this.handle = new WindowInteropHelper(this).Handle; //获取任务栏句柄 IntPtr taskBarInPtr = WindowApi.FindWindow("Shell_TrayWnd", null); this.reBarInPtr = WindowApi.FindWindowEx(taskBarInPtr, (IntPtr)0, "ReBarWindow32", null); WindowApi.SetParent(this.handle, this.reBarInPtr); this.msTaskSwInPtr = WindowApi.FindWindowEx(this.reBarInPtr, (IntPtr)0, "MSTaskSwWClass", null); this.provessor = new PerformanceCounter("Processor Information", "% Processor Time", "_Total"); this.memery = new PerformanceCounter("Memory", "Available MBytes"); this.totleMemory = this.GetPhisicalMemory(); this._timer = new Timer(1000); this._timer.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); this._monitor = new NetworkMonitor(); this._monitor.DownloadEvent += new NetworkMonitorEvent(DownloadSpeedEvent); this._monitor.UploadEvent += new NetworkMonitorEvent(UpdateSpeedEvent); this._monitor.StartMonitoring(); this._timer.Start(); this.RefreshRect(); }
/// <summary> /// 位置刷新 /// </summary> private void RefreshLocation() { try { IntPtr taskBarInPtr = WindowApi.FindWindow("Shell_TrayWnd", null); var reBarInPtr = WindowApi.FindWindowEx(taskBarInPtr, (IntPtr)0, "ReBarWindow32", null); if (this.reBarInPtr != reBarInPtr) { this.reBarInPtr = WindowApi.SetParent(this.handle, reBarInPtr); } } catch { } }
/// <summary> /// 清理内存信息 /// </summary> /// <param name="sender">发送者</param> /// <param name="e">信息</param> private void CleanMemory(object sender, MouseButtonEventArgs e) { Task.Run(() => { GC.Collect(); GC.WaitForPendingFinalizers(); Process[] processes = Process.GetProcesses(); foreach (Process process in processes) { //对于系统进程会拒绝访问,导致出错,此处对异常不进行处理。 try { WindowApi.EmptyWorkingSet(process.Handle); } catch { } } }); }