mirror of
https://github.com/microsoft/PowerToys
synced 2025-09-02 23:45:11 +00:00
* Fix lack of tray icon #268 by handling initial Shell_NotifyIcon failure
This commit is contained in:
@@ -6,20 +6,24 @@
|
|||||||
|
|
||||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||||
|
|
||||||
HWND tray_icon_hwnd = NULL;
|
namespace {
|
||||||
|
HWND tray_icon_hwnd = NULL;
|
||||||
|
|
||||||
// Message code that Windows will use for tray icon notifications.
|
// Message code that Windows will use for tray icon notifications.
|
||||||
UINT wm_icon_notify = 0;
|
UINT wm_icon_notify = 0;
|
||||||
|
|
||||||
// Contains the Windows Message for taskbar creation.
|
// Contains the Windows Message for taskbar creation.
|
||||||
UINT wm_taskbar_restart = 0;
|
UINT wm_taskbar_restart = 0;
|
||||||
UINT wm_run_on_main_ui_thread = 0;
|
UINT wm_run_on_main_ui_thread = 0;
|
||||||
|
|
||||||
NOTIFYICONDATAW tray_icon_data;
|
NOTIFYICONDATAW tray_icon_data;
|
||||||
static bool about_box_shown = false;
|
bool tray_icon_created = false;
|
||||||
|
|
||||||
HMENU h_menu = nullptr;
|
bool about_box_shown = false;
|
||||||
HMENU h_sub_menu = nullptr;
|
|
||||||
|
HMENU h_menu = nullptr;
|
||||||
|
HMENU h_sub_menu = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// Struct to fill with callback and the data. The window_proc is responsible for cleaning it.
|
// Struct to fill with callback and the data. The window_proc is responsible for cleaning it.
|
||||||
struct run_on_main_ui_thread_msg {
|
struct run_on_main_ui_thread_msg {
|
||||||
@@ -77,6 +81,16 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
// Shell_NotifyIcon can fail when we invoke it during the time explorer.exe isn't present/ready to handle it.
|
||||||
|
// We'll also never receive wm_taskbar_restart message if the first call to Shell_NotifyIcon failed, so we use
|
||||||
|
// WM_WINDOWPOSCHANGING which is always received on explorer startup sequence.
|
||||||
|
case WM_WINDOWPOSCHANGING:
|
||||||
|
{
|
||||||
|
if(!tray_icon_created) {
|
||||||
|
tray_icon_created = Shell_NotifyIcon(NIM_ADD, &tray_icon_data) == TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if (message == wm_icon_notify) {
|
if (message == wm_icon_notify) {
|
||||||
switch(lparam) {
|
switch(lparam) {
|
||||||
@@ -110,7 +124,7 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (message == wm_taskbar_restart) {
|
} else if (message == wm_taskbar_restart) {
|
||||||
Shell_NotifyIcon(NIM_ADD, &tray_icon_data);
|
tray_icon_created = Shell_NotifyIcon(NIM_ADD, &tray_icon_data) == TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,6 +168,6 @@ void start_tray_icon() {
|
|||||||
wcscpy_s(tray_icon_data.szTip, sizeof(tray_icon_data.szTip) / sizeof(WCHAR), L"PowerToys");
|
wcscpy_s(tray_icon_data.szTip, sizeof(tray_icon_data.szTip) / sizeof(WCHAR), L"PowerToys");
|
||||||
tray_icon_data.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
|
tray_icon_data.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
|
||||||
|
|
||||||
Shell_NotifyIcon(NIM_ADD, &tray_icon_data);
|
tray_icon_created = Shell_NotifyIcon(NIM_ADD, &tray_icon_data) == TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user