Post a WM_CANCELMODE message to wake up the internal menu handling
code. This fixes the problem of a menu being orphaned when the parent
window disappears, or if the parent loses focus.
diff --git a/controls/menu.c b/controls/menu.c
index 5e1ad37..0ce05da 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -2725,6 +2725,19 @@
if (!MSG_InternalGetMessage( QMSG_WIN32A, &msg, msg.hwnd, mt.hOwnerWnd,
MSGF_MENU, PM_NOREMOVE, !enterIdleSent, &enterIdleSent )) break;
+ /* check if EndMenu() tried to cancel us, by posting this message */
+ if(msg.message == WM_CANCELMODE)
+ {
+ /* we are now out of the loop */
+ fEndMenu = TRUE;
+
+ /* remove the message from the queue */
+ PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
+
+ /* break out of internal loop, ala ESCAPE */
+ break;
+ }
+
TranslateMessage( &msg );
mt.pt = msg.pt;
@@ -4157,11 +4170,18 @@
*/
void WINAPI EndMenu(void)
{
- /*
- * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
- */
+ /* if we are in the menu code, and it is active */
+ if (fEndMenu == FALSE && MENU_IsMenuActive())
+ {
+ /* terminate the menu handling code */
+ fEndMenu = TRUE;
- fEndMenu = TRUE;
+ /* needs to be posted to wakeup the internal menu handler */
+ /* which will now terminate the menu, in the event that */
+ /* the main window was minimized, or lost focus, so we */
+ /* don't end up with an orphaned menu */
+ PostMessageA( pTopPopupWnd->hwndSelf, WM_CANCELMODE, 0, 0);
+ }
}