[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
This commit is contained in:
Andreas Opferkuch
2018-07-29 14:41:25 +02:00
committed by GitHub
parent 89568e800c
commit 2ae960fcfc

1
tray.h
View File

@@ -230,6 +230,7 @@ static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam,
if (lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) { if (lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) {
POINT p; POINT p;
GetCursorPos(&p); GetCursorPos(&p);
SetForegroundWindow(hwnd);
WORD cmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | WORD cmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON |
TPM_RETURNCMD | TPM_NONOTIFY, TPM_RETURNCMD | TPM_NONOTIFY,
p.x, p.y, 0, hwnd, NULL); p.x, p.y, 0, hwnd, NULL);