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