From ce0fcf9c9724df7b15accc05d1efbc2751e620d2 Mon Sep 17 00:00:00 2001 From: lx-s Date: Wed, 8 Jul 2026 14:45:39 +0200 Subject: [PATCH] use new trayicon version --- WinMute/TrayIcon.cpp | 13 +++++-------- WinMute/WinMute.cpp | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/WinMute/TrayIcon.cpp b/WinMute/TrayIcon.cpp index 4bca8d4..460c015 100644 --- a/WinMute/TrayIcon.cpp +++ b/WinMute/TrayIcon.cpp @@ -107,7 +107,6 @@ void TrayIcon::ChangeIcon(HICON hNewIcon) if (oldIconVisible) { NOTIFYICONDATA tnid{0}; tnid.cbSize = sizeof(NOTIFYICONDATA); - tnid.uVersion = NOTIFYICON_VERSION_4; tnid.hWnd = hWnd_; tnid.uID = trayID_; tnid.hIcon = hIcon_; @@ -142,13 +141,11 @@ void TrayIcon::ShowPopup(const std::wstring& title, } NOTIFYICONDATAW tnid{0}; tnid.cbSize = sizeof(tnid); - tnid.uVersion = NOTIFYICON_VERSION_4; tnid.hWnd = hWnd_; tnid.uID = trayID_; tnid.uFlags = NIF_INFO | NIF_SHOWTIP; tnid.dwInfoFlags = NIIF_INFO | NIIF_NOSOUND | NIIF_LARGE_ICON | NIIF_RESPECT_QUIET_TIME; - tnid.uTimeout = 10 * 1000; StringCchCopy(tnid.szInfoTitle, ARRAY_SIZE(tnid.szInfoTitle), title.c_str()); StringCchCopy(tnid.szInfo, ARRAY_SIZE(tnid.szInfo), text.c_str()); @@ -178,11 +175,13 @@ bool TrayIcon::AddNotifyIcon() if (SUCCEEDED(StringCchCopy(tnid.szTip, ARRAY_SIZE(tnid.szTip), tooltip_.c_str()))) { - DWORD result = Shell_NotifyIconW(NIM_ADD, &tnid); - if (result == 0) { + BOOL result = Shell_NotifyIconW(NIM_ADD, &tnid); + if (result) { + // Opt in to NOTIFYICON_VERSION_4 message semantics; uVersion is + // only honored by NIM_SETVERSION. result = Shell_NotifyIconW(NIM_SETVERSION, &tnid); } - return result != 0; + return result != FALSE; } return false; } @@ -191,7 +190,6 @@ bool TrayIcon::RemoveNotifyIcon() { NOTIFYICONDATAW tnid{0}; tnid.cbSize = sizeof(tnid); - tnid.uVersion = NOTIFYICON_VERSION_4; tnid.hWnd = hWnd_; tnid.uID = trayID_; @@ -202,7 +200,6 @@ bool TrayIcon::ChangeText() { NOTIFYICONDATAW tnid{0}; tnid.cbSize = sizeof(tnid); - tnid.uVersion = NOTIFYICON_VERSION_4; tnid.hWnd = hWnd_; tnid.uID = trayID_; tnid.uFlags = NIF_TIP; diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index 1eb796b..154bd04 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -339,7 +339,7 @@ bool WinMute::LoadSettings() } else { muteCtrl_.SetMuteOnBluetoothDisconnect(true); const bool muteOnWithDeviceList = settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST); - btDetector_.SetDeviceList(settings_.GetBluetoothDevicesA(), muteOnWithDeviceList); + btDetector_.SetDeviceList(settings_.GetBluetoothDevices(), muteOnWithDeviceList); } } @@ -564,13 +564,15 @@ LRESULT WinMute::OnCommand(HWND hWnd, WPARAM wParam, LPARAM) return 0; } -LRESULT WinMute::OnTrayIcon(HWND hWnd, WPARAM, LPARAM lParam) +LRESULT WinMute::OnTrayIcon(HWND hWnd, WPARAM wParam, LPARAM lParam) { - if (LOWORD(lParam) == WM_CONTEXTMENU || - lParam == WM_LBUTTONUP || - lParam == WM_RBUTTONUP) { - POINT p = { 0 }; - GetCursorPos(&p); + // NOTIFYICON_VERSION_4 semantics: LOWORD(lParam) carries the event, + // HIWORD(lParam) the icon ID and wParam the anchor coordinates. + const UINT event = LOWORD(lParam); + if (event == WM_CONTEXTMENU || + event == NIN_SELECT || + event == NIN_KEYSELECT) { + const POINT p{ GET_X_LPARAM(wParam), GET_Y_LPARAM(wParam) }; SetForegroundWindow(hWnd); TrackPopupMenuEx( GetSubMenu(hTrayMenu_, 0), @@ -582,7 +584,9 @@ LRESULT WinMute::OnTrayIcon(HWND hWnd, WPARAM, LPARAM lParam) LRESULT WinMute::OnUpdatePopup(HWND hWnd, WPARAM, LPARAM lParam) { - if (lParam == NIN_BALLOONUSERCLICK) { + // NOTIFYICON_VERSION_4 semantics: LOWORD(lParam) carries the event. + const UINT event = LOWORD(lParam); + if (event == NIN_BALLOONUSERCLICK) { const bool betaUpdates = settings_.QueryValue(SettingsKey::CHECK_FOR_BETA_UPDATE) != 0; if (betaUpdates && updateInfo_.beta.shouldUpdate) { LaunchBrowser(hWnd, updateInfo_.beta.downloadUrl); @@ -590,7 +594,7 @@ LRESULT WinMute::OnUpdatePopup(HWND hWnd, WPARAM, LPARAM lParam) LaunchBrowser(hWnd, updateInfo_.stable.downloadUrl); } } - if (lParam == NIN_BALLOONHIDE || lParam == NIN_BALLOONTIMEOUT || lParam == NIN_BALLOONUSERCLICK) { + if (event == NIN_BALLOONHIDE || event == NIN_BALLOONTIMEOUT || event == NIN_BALLOONUSERCLICK) { updateTray_.Hide(); } return 0; -- 2.43.0