🐛 高分屏下的鼠标位置

This commit is contained in:
BookerLiu
2024-08-08 10:56:00 +08:00
parent 2a4f9a9bda
commit 39251b66f6
3 changed files with 171 additions and 101 deletions

View File

@@ -11,6 +11,7 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Cursors = System.Windows.Input.Cursors;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
@@ -22,7 +23,7 @@ namespace GeekDesk.Control.Windows
/// </summary>
public partial class PixelColorPickerWindow : IWindowCommon
{
private static int PIXEL_REC_LENGTH = 20;
private static int PIXEL_REC_LENGTH = 10;
private static readonly int MIN_LENGTH = 10;
private static readonly int MAX_LENGTH = 50;
@@ -73,11 +74,7 @@ namespace GeekDesk.Control.Windows
//获取缩放比例
double scale = ScreenUtil.GetScreenScalingFactor();
//如果主显示器是最左边和最上边,则显示主显示器的缩放比例,反之则缩放比例不添加缩放比例
if (Screen.PrimaryScreen.Bounds.X != x || Screen.PrimaryScreen.Bounds.Y != y)
{
scale = 1;
}
this.Width = allWidth;
this.Height = allHeight;
@@ -173,23 +170,25 @@ namespace GeekDesk.Control.Windows
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr onj);
// Constants for DPI
private const int HORZRES = 8;
private const int VERTRES = 10;
private const int LOGPIXELSX = 88;
private const int LOGPIXELSY = 90;
private static float GetDpi(bool isX)
{
IntPtr hdc = WindowUtil.GetDC(IntPtr.Zero);
int dpi = isX ? WindowUtil.GetDeviceCaps(hdc, LOGPIXELSX) : WindowUtil.GetDeviceCaps(hdc, LOGPIXELSY);
WindowUtil.ReleaseDC(IntPtr.Zero, hdc);
return dpi / 96f;
}
private void SetPixelAbout(MouseEventArgs e)
{
VisualBrush b = (VisualBrush)PixelBG.Fill;
Point pos;
//if (e == null)
//{
// pos = MouseUtil.GetMousePosition();
//}
//else
//{
// pos = e.MouseDevice.GetPosition(DesktopBG);
//}
pos = Mouse.GetPosition(this);
Point pos = Mouse.GetPosition(this);
Rect viewBox = b.Viewbox;
@@ -203,30 +202,26 @@ namespace GeekDesk.Control.Windows
double x = pos.X + 10;
double y = pos.Y + 10;
if (x + ColorCanvas.Width > SystemParameters.VirtualScreenWidth)
//获取缩放比例
double scale = ScreenUtil.GetScreenScalingFactor();
if (x + ColorCanvas.Width > this.Width / scale)
{
x = pos.X - ColorCanvas.Width - 10;
}
if (y + ColorCanvas.Height > SystemParameters.VirtualScreenHeight)
if (y + ColorCanvas.Height > this.Height / scale)
{
y = pos.Y - ColorCanvas.Height - 10;
}
Canvas.SetLeft(ColorCanvas, x);
Canvas.SetTop(ColorCanvas, y);
//Color wColor = GetColorAtPosition(pos);
//获取缩放比例
double scale = ScreenUtil.GetScreenScalingFactor();
//如果主显示器是最左边和最上边,则显示主显示器的缩放比例,反之则缩放比例不添加缩放比例
if (Screen.PrimaryScreen.Bounds.X != x || Screen.PrimaryScreen.Bounds.Y != y)
{
scale = 1;
}
//Console.WriteLine(DesktopBG.Width + "=" + DesktopBG.Height + "=" + pos.X + "=" + pos.Y);
Color wColor = GetColorAtPosition(pos);