From 527c27f67556cc735dd850bf78b93e19070f72f6 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 23 Jul 2025 13:28:50 +0800 Subject: [PATCH] Remove System.Windows.Forms.Screen reference --- Flow.Launcher/MainWindow.xaml.cs | 41 +++++++++---------- Flow.Launcher/Msg.xaml.cs | 3 +- Flow.Launcher/MsgWithButton.xaml.cs | 3 +- .../SettingsPaneGeneralViewModel.cs | 6 +-- Flow.Launcher/SettingWindow.xaml.cs | 7 ++-- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 2ddce8190..429a4aece 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.Linq; using System.Media; @@ -30,7 +30,6 @@ using DataObject = System.Windows.DataObject; using Key = System.Windows.Input.Key; using MouseButtons = System.Windows.Forms.MouseButtons; using NotifyIcon = System.Windows.Forms.NotifyIcon; -using Screen = System.Windows.Forms.Screen; namespace Flow.Launcher { @@ -532,7 +531,7 @@ namespace Flow.Launcher double yRatio = mousePos.Y / maxHeight; // Current monitor information - var screen = Screen.FromHandle(new WindowInteropHelper(this).Handle); + var screen = MonitorInfo.GetNearestDisplayMonitor(new WindowInteropHelper(this).Handle); var workingArea = screen.WorkingArea; var screenLeftTop = Win32Helper.TransformPixelsToDIP(this, workingArea.X, workingArea.Y); @@ -954,36 +953,36 @@ namespace Flow.Launcher } } - private Screen SelectedScreen() + private MonitorInfo SelectedScreen() { - Screen screen; + MonitorInfo screen; switch (_settings.SearchWindowScreen) { case SearchWindowScreens.Cursor: - screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - break; - case SearchWindowScreens.Primary: - screen = Screen.PrimaryScreen; + screen = MonitorInfo.GetCursorDisplayMonitor(); break; case SearchWindowScreens.Focus: - var foregroundWindowHandle = Win32Helper.GetForegroundWindow(); - screen = Screen.FromHandle(foregroundWindowHandle); + screen = MonitorInfo.GetNearestDisplayMonitor(Win32Helper.GetForegroundWindow()); + break; + case SearchWindowScreens.Primary: + screen = MonitorInfo.GetPrimaryDisplayMonitor(); break; case SearchWindowScreens.Custom: - if (_settings.CustomScreenNumber <= Screen.AllScreens.Length) - screen = Screen.AllScreens[_settings.CustomScreenNumber - 1]; + var allScreens = MonitorInfo.GetDisplayMonitors(); + if (_settings.CustomScreenNumber <= allScreens.Count) + screen = allScreens[_settings.CustomScreenNumber - 1]; else - screen = Screen.AllScreens[0]; + screen = allScreens[0]; break; default: - screen = Screen.AllScreens[0]; + screen = MonitorInfo.GetDisplayMonitors()[0]; break; } - return screen ?? Screen.AllScreens[0]; + return screen ?? MonitorInfo.GetDisplayMonitors()[0]; } - private double HorizonCenter(Screen screen) + private double HorizonCenter(MonitorInfo screen) { var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); @@ -991,7 +990,7 @@ namespace Flow.Launcher return left; } - private double VerticalCenter(Screen screen) + private double VerticalCenter(MonitorInfo screen) { var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); var dip2 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); @@ -999,7 +998,7 @@ namespace Flow.Launcher return top; } - private double HorizonRight(Screen screen) + private double HorizonRight(MonitorInfo screen) { var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); @@ -1007,14 +1006,14 @@ namespace Flow.Launcher return left; } - private double HorizonLeft(Screen screen) + private double HorizonLeft(MonitorInfo screen) { var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var left = dip1.X + 10; return left; } - public double VerticalTop(Screen screen) + private double VerticalTop(MonitorInfo screen) { var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); var top = dip1.Y + 10; diff --git a/Flow.Launcher/Msg.xaml.cs b/Flow.Launcher/Msg.xaml.cs index 923c3692f..6063e489c 100644 --- a/Flow.Launcher/Msg.xaml.cs +++ b/Flow.Launcher/Msg.xaml.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Windows; -using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media.Animation; using Flow.Launcher.Infrastructure; @@ -16,7 +15,7 @@ namespace Flow.Launcher public Msg() { InitializeComponent(); - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var screen = MonitorInfo.GetCursorDisplayMonitor(); var dipWorkingArea = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, screen.WorkingArea.Height); diff --git a/Flow.Launcher/MsgWithButton.xaml.cs b/Flow.Launcher/MsgWithButton.xaml.cs index 8ccd19c46..89149c2d4 100644 --- a/Flow.Launcher/MsgWithButton.xaml.cs +++ b/Flow.Launcher/MsgWithButton.xaml.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Windows; -using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media.Animation; using Flow.Launcher.Infrastructure; @@ -16,7 +15,7 @@ namespace Flow.Launcher public MsgWithButton() { InitializeComponent(); - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var screen = MonitorInfo.GetCursorDisplayMonitor(); var dipWorkingArea = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, screen.WorkingArea.Height); diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index 21444ccee..5057ebb44 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; @@ -111,9 +111,9 @@ public partial class SettingsPaneGeneralViewModel : BaseModel { get { - var screens = Screen.AllScreens; + var screens = MonitorInfo.GetDisplayMonitors(); var screenNumbers = new List(); - for (int i = 1; i <= screens.Length; i++) + for (int i = 1; i <= screens.Count; i++) { screenNumbers.Add(i); } diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index c1c0f96a7..b4f6bcf69 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -10,7 +10,6 @@ using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.SettingPages.Views; using Flow.Launcher.ViewModel; using ModernWpf.Controls; -using Screen = System.Windows.Forms.Screen; namespace Flow.Launcher; @@ -202,7 +201,7 @@ public partial class SettingWindow private static bool IsPositionValid(double top, double left) { - foreach (var screen in Screen.AllScreens) + foreach (var screen in MonitorInfo.GetDisplayMonitors()) { var workingArea = screen.WorkingArea; @@ -217,7 +216,7 @@ public partial class SettingWindow private double WindowLeft() { - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var screen = MonitorInfo.GetCursorDisplayMonitor(); var dip1 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); var dip2 = Win32Helper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); var left = (dip2.X - ActualWidth) / 2 + dip1.X; @@ -226,7 +225,7 @@ public partial class SettingWindow private double WindowTop() { - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var screen = MonitorInfo.GetCursorDisplayMonitor(); var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); var dip2 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); var top = (dip2.Y - ActualHeight) / 2 + dip1.Y - 20;