From 2ae960fcfcc0896140d48d7c7e14df8139ee5634 Mon Sep 17 00:00:00 2001 From: Andreas Opferkuch Date: Sun, 29 Jul 2018 14:41:25 +0200 Subject: [PATCH] [win] close menu if user clicks outside See also here ("Important: If you implement a context menu, it's vital that you set your window to the foreground before calling TrackPopupMenu to ensure the menu closes properly."): https://www.codeproject.com/Articles/4768/Basic-use-of-Shell-NotifyIcon-in-Win32 --- tray.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tray.h b/tray.h index fac1739..4ba47ea 100644 --- a/tray.h +++ b/tray.h @@ -230,6 +230,7 @@ static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, if (lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) { POINT p; GetCursorPos(&p); + SetForegroundWindow(hwnd); WORD cmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, p.x, p.y, 0, hwnd, NULL);