diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a3ffb03 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +################################################################################ +# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 +################################################################################ + +/.dotnet_cli/.dotnet +/.vs +/bin/* +/obj/* +/LiteMonitor.Updater/* \ No newline at end of file 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); // 更新悬浮窗模式 (支持热切换)