mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-28 08:14:18 +02:00
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:
parent
703e2e1726
commit
6459905816
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user