生活随笔
收集整理的這篇文章主要介紹了
Monitor 监测CPU与内存
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
WPF開發者QQ群:?340500857?
開發者:幸運文字-徐守來
接著上一篇?優化后
效果如下:
強烈建議 Win10?使用。
增加如下
一、解決退出時閃屏和閃爍問題代碼如下:
private void ExitMonitor(object sender, RoutedEventArgs e){this.OnClose();this.CloseDeskBand();ExecCMD("/nologo /unregister \"{0}\"", "MonitorLibrary.dll");}
二、獲取當前操作系統 是淺色還是暗色:
bool IsLight() {bool isLightMode = true;try{var v = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", "1");if (v != null && v.ToString() == "0")isLightMode = false;}catch { }return isLightMode;}
三、讀取任務欄顏色:(當時是為了win7使用問題。)
[DllImport("shell32.dll")]private static extern IntPtr SHAppBarMessage(int msg, ref APPBARDATA data);[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]private static extern int BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);private struct APPBARDATA{public int cbSize;public IntPtr hWnd;public int uCallbackMessage;public int uEdge;public RECT rc;public IntPtr lParam;}private struct RECT{public int left, top, right, bottom;}private const int ABM_GETTASKBARPOS = 5;private static Rectangle GetTaskbarPosition()
{APPBARDATA data = new APPBARDATA();data.cbSize = Marshal.SizeOf(data);IntPtr retval = SHAppBarMessage(ABM_GETTASKBARPOS, ref data);if (retval == IntPtr.Zero){throw new Win32Exception("error");}return new Rectangle(data.rc.left, data.rc.top, data.rc.right - data.rc.left, data.rc.bottom - data.rc.top);}private static System.Drawing.Color GetColourAt(System.Drawing.Point location)
{using (Bitmap screenPixel = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb))using (Graphics gdest = Graphics.FromImage(screenPixel)){using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero)){IntPtr hSrcDC = gsrc.GetHdc();IntPtr hDC = gdest.GetHdc();int retval = BitBlt(hDC, 0, 0, 1, 1, hSrcDC, location.X, location.Y, (int)CopyPixelOperation.SourceCopy);gdest.ReleaseHdc();gsrc.ReleaseHdc();}return screenPixel.GetPixel(0, 0);}}
源碼地址1QQ群->“文件”->“開源項目”->" 源碼任務欄CPU監測類似魯大師Win10Monitor.zip
源碼地址2:
https://github.com/shoulai/Monitor
WPF開發者QQ群:?340500857?
blogs:?https://www.cnblogs.com/yanjinhua
Github:https://github.com/yanjinhuagood
作者:?幸運文字-徐守來、驚鏵
出處:https://www.cnblogs.com/yanjinhua
版權:本作品采用「署名-非商業性使用-相同方式共享 4.0 國際」許可協議進行許可。
轉載請著名作者 出處 https://github.com/yanjinhuagood
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的Monitor 监测CPU与内存的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。