Skip to content

Commit 14e35b2

Browse files
committed
[feat] support manually remove tray icon.
1 parent a1f9cda commit 14e35b2

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ language: **EN** | [中文](./README_CN.md)
2222

2323
6. When the main program exits, all hidden windows will be restored to visible and all related tray icons will be deleted.
2424

25+
7. To manually remove a tray icon: Hold down Ctrl and double-click the icon. The corresponding window will be visible again and will no longer be automatically hidden.
26+
2527
### Other matters
2628

2729
+ Currently, the main window of this program has no content and is blank. This is normal.

README_CN.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ language: [EN](./README_CN.md) | **中文**
2222

2323
6. 当主程序退出时,会将所有被隐藏的窗口恢复为可见,并删除所有相关的托盘图标。
2424

25+
7. 如需手动移除某个托盘图标:按住 Ctrl,左键双击相应的图标即可。其对应的窗口将恢复可见,且不再自动隐藏。
26+
2527
### 其他事项
2628

2729
+ 目前,本程序的主窗口并没有什么内容,是一片空白,这是正常的。

src/TrayIconManager.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,23 @@ void TrayIconManager::HandleTrayIconMessage(WPARAM wParam, LPARAM lParam)
6767
}
6868
else if (lParam == WM_LBUTTONDBLCLK)
6969
{
70-
if (wParam == nidMain.uID) ShowWindow(nidMain.hWnd, SW_RESTORE); // 双击主程序托盘图标时,显示窗口
71-
else WindowManager::ToggleWindowVisibilityByTrayIconId(static_cast<UINT>(wParam)); // 双击被隐藏程序的托盘图标时,切换窗口显示状态
70+
if (GetKeyState(VK_CONTROL) & 0x8000) // Ctrl+双击托盘图标,移除对应的托盘图标,并显示窗口
71+
{
72+
for (auto& [hwnd, nid, manuallyShown] : WindowManager::hiddenWindows)
73+
{
74+
if (nid.uID == wParam) // 根据 nid 找到对应的被隐藏窗口
75+
{
76+
manuallyShown = true; // 标记为手动显示,防止被意外隐藏
77+
ShowWindow(hwnd, SW_SHOW);
78+
Shell_NotifyIconW(NIM_DELETE, &nid);
79+
break;
80+
}
81+
}
82+
}
83+
else // Ctrl未按下,双击托盘图标,切换窗口可见性
84+
{
85+
if (wParam == nidMain.uID) ShowWindow(nidMain.hWnd, IsWindowVisible(nidMain.hWnd) ? SW_HIDE : SW_SHOW);
86+
else WindowManager::ToggleWindowVisibilityByTrayIconId(static_cast<UINT>(wParam)); // 双击被隐藏程序的托盘图标时,切换窗口显示状态
87+
}
7288
}
7389
}

0 commit comments

Comments
 (0)