diff --git a/Control/Windows/PixelColorPickerWindow.xaml.cs b/Control/Windows/PixelColorPickerWindow.xaml.cs index 06f151f..a1917aa 100644 --- a/Control/Windows/PixelColorPickerWindow.xaml.cs +++ b/Control/Windows/PixelColorPickerWindow.xaml.cs @@ -39,7 +39,11 @@ namespace GeekDesk.Control.Windows { InitializeComponent(); this.colorPicker = colorPicker; - SetProcessDPIAware(); + try + { + SetProcessDPIAware(); + } + catch (Exception e) { } ColorPickerWindow_Init(); } @@ -58,9 +62,12 @@ namespace GeekDesk.Control.Windows DesktopBG.Height = this.Height; this.Topmost = true; + //获取缩放比例 + double scale = ScreenUtil.GetScreenScalingFactor(); + bgBitmap = new System.Drawing.Bitmap( - Screen.AllScreens[0].Bounds.Width, - Screen.AllScreens[0].Bounds.Height, + (int)(Width * scale), + (int)(Height * scale), System.Drawing.Imaging.PixelFormat.Format32bppArgb ); diff --git a/Plugins/ShowSeconds/SecondsWindow.xaml.cs b/Plugins/ShowSeconds/SecondsWindow.xaml.cs index e721976..47047d3 100644 --- a/Plugins/ShowSeconds/SecondsWindow.xaml.cs +++ b/Plugins/ShowSeconds/SecondsWindow.xaml.cs @@ -154,7 +154,7 @@ namespace ShowSeconds //获取实际坐标 windows可能会有缩放 IntPtr hdc = GetDC(IntPtr.Zero); - double scale = GetScreenScalingFactor(); + double scale = ScreenUtil.GetScreenScalingFactor(); x = (int)(x / scale); y = (int)(y / scale); @@ -268,7 +268,7 @@ namespace ShowSeconds double h = 1080; double width = SystemParameters.PrimaryScreenWidth; double height = SystemParameters.PrimaryScreenHeight; - double scale = GetScreenScalingFactor(); + double scale = ScreenUtil.GetScreenScalingFactor(); Console.WriteLine("bef:" + w2 / w * width); Console.WriteLine("af:" + w2 / w * width * scale); @@ -347,23 +347,9 @@ namespace ShowSeconds //####################################################### - public const int HORZRES = 8; - public const int VERTRES = 10; - public const int DESKTOPVERTRES = 117; - public const int DESKTOPHORZRES = 118; + - private static double GetScreenScalingFactor() - { - var g = Graphics.FromHwnd(IntPtr.Zero); - IntPtr desktop = g.GetHdc(); - var physicalScreenHeight = GetDeviceCaps(desktop, (int)DESKTOPVERTRES); - - var screenScalingFactor = - (double)physicalScreenHeight / SystemParameters.PrimaryScreenHeight; - //SystemParameters.PrimaryScreenHeight; - - return screenScalingFactor; - } + /// @@ -385,7 +371,6 @@ namespace ShowSeconds public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); [DllImport("user32")] public static extern bool GetCursorPos(out System.Drawing.Point pt); - [DllImport("gdi32")] - static extern int GetDeviceCaps(IntPtr hdc, int nIndex); + } } diff --git a/Util/ScreenUtil.cs b/Util/ScreenUtil.cs index e35ce04..19c6c44 100644 --- a/Util/ScreenUtil.cs +++ b/Util/ScreenUtil.cs @@ -120,5 +120,30 @@ namespace GeekDesk.Util return screenPixel.GetPixel(0, 0); } + + [DllImport("gdi32")] + static extern int GetDeviceCaps(IntPtr hdc, int nIndex); + + public const int HORZRES = 8; + public const int VERTRES = 10; + public const int DESKTOPVERTRES = 117; + public const int DESKTOPHORZRES = 118; + /// + /// 获取屏幕缩放比例 + /// + /// + public static double GetScreenScalingFactor() + { + var g = Graphics.FromHwnd(IntPtr.Zero); + IntPtr desktop = g.GetHdc(); + var physicalScreenHeight = GetDeviceCaps(desktop, (int)DESKTOPVERTRES); + + var screenScalingFactor = + (double)physicalScreenHeight / SystemParameters.PrimaryScreenHeight; + //SystemParameters.PrimaryScreenHeight; + + return screenScalingFactor; + } + } }