From 8b08fb3d076be396293340140cd3d4d090f4ca51 Mon Sep 17 00:00:00 2001 From: Kang Yu Date: Fri, 1 Mar 2024 12:11:55 -0800 Subject: [PATCH] #300, avoid hide the same window to tray multiple times --- .../Common/MinimizeToNotify.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Ninjacrab.PersistentWindows.Solution/Common/MinimizeToNotify.cs b/Ninjacrab.PersistentWindows.Solution/Common/MinimizeToNotify.cs index 3f7adb9..ad62a0a 100644 --- a/Ninjacrab.PersistentWindows.Solution/Common/MinimizeToNotify.cs +++ b/Ninjacrab.PersistentWindows.Solution/Common/MinimizeToNotify.cs @@ -1,17 +1,18 @@  using System; +using System.Collections.Generic; using System.Windows.Forms; using System.Drawing; using System.Text; using System.Timers; - using PersistentWindows.Common.WinApiBridge; namespace PersistentWindows.Common.Minimize2Tray { public class MinimizeToTray : IDisposable { + private static HashSet _trayWindows = new HashSet(); private NotifyIcon _systemTrayIcon = null; private IntPtr _hwnd; private string _window_txt; @@ -19,12 +20,16 @@ namespace PersistentWindows.Common.Minimize2Tray static public void Create(IntPtr hwnd) { + if (_trayWindows.Contains(hwnd)) + return; + // clear ctrl state User32.GetAsyncKeyState(0x11); bool ctrl_key_pressed = (User32.GetAsyncKeyState(0x11) & 0x8000) != 0; if (!ctrl_key_pressed) return; + _trayWindows.Add(hwnd); new MinimizeToTray(hwnd); } @@ -135,6 +140,8 @@ namespace PersistentWindows.Common.Minimize2Tray { if (disposing) { + _trayWindows.Remove(_hwnd); + _systemTrayIcon.Visible = false; //User32.ShowWindowAsync(_hwnd, (int)ShowWindowCommands.Show); User32.ShowWindowAsync(_hwnd, (int)ShowWindowCommands.Restore);