Fix Notepad++ try icon lost after Windows Taskbar crashes & being recreate

Re-add the tray icon when the taskbar is re-created.

Fix #16588, close #16589
This commit is contained in:
Anthony Lee Stark 2025-05-23 21:50:43 +07:00 committed by Don Ho
parent 703e2e1726
commit 6459905816
3 changed files with 27 additions and 1 deletions

View File

@ -41,6 +41,7 @@ using namespace std;
#endif
std::atomic<bool> g_bNppExitFlag{ false };
const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(L"TaskbarCreated");
struct SortTaskListPred final
@ -4365,6 +4366,16 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return TRUE;
}
else if (message == WM_TASKBARCREATED)
{
if (!_pTrayIco)
return TRUE;
// re-add tray icon
_pTrayIco->reAddTrayIcon();
return TRUE;
}
return ::DefWindowProc(hwnd, message, wParam, lParam);
}
}

View File

@ -27,7 +27,6 @@ trayIconControler::trayIconControler(HWND hwnd, UINT uID, UINT uCBMsg, HICON hic
_nid.hIcon = hicon;
wcscpy_s(_nid.szTip, tip);
::RegisterWindowMessage(L"TaskbarCreated");
_isIconShown = false;
}
@ -44,3 +43,18 @@ int trayIconControler::doTrayIcon(DWORD op)
return 0;
}
int trayIconControler::reAddTrayIcon()
{
if (!_isIconShown)
return -1;
// we only re-add the tray icon when it has been lost and no longer exists,
// but we still delete it first to ensure it's not duplicated
// due to an incorrect call or something
::Shell_NotifyIcon(NIM_DELETE, &_nid);
// reset state and re-add tray icon
_isIconShown = false;
return doTrayIcon(ADD);
}

View File

@ -32,6 +32,7 @@ public:
trayIconControler(HWND hwnd, UINT uID, UINT uCBMsg, HICON hicon, const wchar_t *tip);
int doTrayIcon(DWORD op);
bool isInTray() const {return _isIconShown;};
int reAddTrayIcon();
private:
NOTIFYICONDATA _nid;