Skip to content

Commit 34f374c

Browse files
committed
Fix Windows context menu not closing when clicking outside
1 parent d7ec4be commit 34f374c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/tray_manager/windows/tray_manager_plugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ void TrayManagerPlugin::PopUpContextMenu(
361361
}
362362
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, static_cast<int>(x),
363363
static_cast<int>(y), 0, hWnd, NULL);
364+
// IMPORTANT: Post a benign message to the window to work around a Windows bug.
365+
// Without this, the menu won't close when clicking outside of it.
366+
// This is documented in the official TrackPopupMenu API documentation.
367+
// See: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-trackpopupmenu
368+
PostMessage(hWnd, WM_NULL, 0, 0);
364369
result->Success(flutter::EncodableValue(true));
365370
}
366371

0 commit comments

Comments
 (0)