From 5c5f25cc615d608c1e81eb42bd266d0b684eaef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E6=84=8FJily?= Date: Thu, 19 Mar 2026 00:07:18 +0800 Subject: [PATCH 1/2] Fixed the issue of the secondary screen's taskbar becoming transparent after restarting in mixed DPI multi-screen setups. --- .gitignore | 10 ++++++++++ src/System/Program.cs | 3 ++- src/UI/Helpers/TaskbarWinHelper.cs | 17 +++++++++++------ src/UI/TaskbarForm.cs | 8 +++++--- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3cdf42a --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +################################################################################ +# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 +################################################################################ + +/.dotnet_cli/.dotnet +/.vs +/bin/Debug/net8.0-windows +/LiteMonitor.Updater/obj +/obj +/bin/Debug diff --git a/src/System/Program.cs b/src/System/Program.cs index 38eb757..38e9941 100644 --- a/src/System/Program.cs +++ b/src/System/Program.cs @@ -84,6 +84,7 @@ static void Main() try { // ★★★ 3. 启动应用 ★★★ + Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); ApplicationConfiguration.Initialize(); Application.Run(new MainForm()); } @@ -148,4 +149,4 @@ static void LogCrash(Exception? ex, string source) } } } -} \ No newline at end of file +} diff --git a/src/UI/Helpers/TaskbarWinHelper.cs b/src/UI/Helpers/TaskbarWinHelper.cs index 371fcf5..2903d49 100644 --- a/src/UI/Helpers/TaskbarWinHelper.cs +++ b/src/UI/Helpers/TaskbarWinHelper.cs @@ -215,7 +215,7 @@ private IntPtr FindSecondaryTaskbar(Screen screen) if (screen.Bounds.Contains(r.Location) || screen.Bounds.IntersectsWith(r)) return hWnd; } - return FindWindow("Shell_TrayWnd", null); + return IntPtr.Zero; } public Rectangle GetTaskbarRect(IntPtr hTaskbar, string targetDevice) @@ -264,7 +264,7 @@ public Rectangle GetTaskbarRect(IntPtr hTaskbar, string targetDevice) if (!isVertical) { - int dpi = GetTaskbarDpi(); + int dpi = GetTaskbarDpi(hTaskbar); int standardHeight = (int)Math.Round(48.0 * dpi / 96.0); if (rectPhys.Height > (standardHeight * 0.8)) @@ -312,16 +312,21 @@ public static bool IsCenterAligned() catch { return false; } } - public static int GetTaskbarDpi() + public static int GetTaskbarDpi(IntPtr hWnd) { - IntPtr taskbar = FindWindow("Shell_TrayWnd", null); - if (taskbar != IntPtr.Zero) + if (hWnd != IntPtr.Zero) { - try { return (int)GetDpiForWindow(taskbar); } catch { } + try { return (int)GetDpiForWindow(hWnd); } catch { } } return 96; } + public static int GetTaskbarDpi() + { + IntPtr taskbar = FindWindow("Shell_TrayWnd", null); + return GetTaskbarDpi(taskbar); + } + public static int GetWidgetsWidth() { int dpi = GetTaskbarDpi(); diff --git a/src/UI/TaskbarForm.cs b/src/UI/TaskbarForm.cs index fa3972e..f39fbe4 100644 --- a/src/UI/TaskbarForm.cs +++ b/src/UI/TaskbarForm.cs @@ -57,12 +57,11 @@ public TaskbarForm(Settings cfg, UIController ui, MainForm mainForm) TopMost = false; DoubleBuffered = true; - ReloadLayout(); - _bizHelper.CheckTheme(true); _bizHelper.FindHandles(); _bizHelper.AttachToTaskbar(); + ReloadLayout(); _winHelper.ApplyLayeredStyle(_bizHelper.TransparentKey, _cfg.TaskbarClickThrough); _timer.Interval = Math.Max(_cfg.RefreshMs, 60); @@ -79,7 +78,10 @@ public void ReloadLayout() { _layout = new HorizontalLayout(ThemeManager.Current, 300, LayoutMode.Taskbar, _cfg); _lastLayoutSignature = ""; // 重置签名,强制重算 - _winHelper.ApplyLayeredStyle(_bizHelper.TransparentKey, _cfg.TaskbarClickThrough); + if (IsHandleCreated) + { + _winHelper.ApplyLayeredStyle(_bizHelper.TransparentKey, _cfg.TaskbarClickThrough); + } _bizHelper.CheckTheme(true); // 更新悬浮窗模式 (支持热切换) From 58cadb4c55bfe41a27c13d61ccf1f20e10ed6fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E6=84=8FJily?= Date: Thu, 19 Mar 2026 15:10:07 +0800 Subject: [PATCH 2/2] ignore --- .gitignore | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 3cdf42a..a3ffb03 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ /.dotnet_cli/.dotnet /.vs -/bin/Debug/net8.0-windows -/LiteMonitor.Updater/obj -/obj -/bin/Debug +/bin/* +/obj/* +/LiteMonitor.Updater/* \ No newline at end of file