DestroyMenu: Check if the menu is still used (fix for bug 1486)

Michael Kaufmann hallo at michael-kaufmann.ch
Sun Sep 5 10:02:37 CDT 2004


Some applications call DestroyMenu for menus that are still displayed in 
a window.  We need to check if a menu is still used and set the window's 
menu handle to NULL if that's the case.

This patch fixes the important bug 1486.

Changelog:
  - DestroyMenu: Check if the menu is still displayed and adjust the 
window's menu handle

-------------- next part --------------
Index: dlls/user/menu.c
===================================================================
RCS file: /home/wine/wine/dlls/user/menu.c,v
retrieving revision 1.1
diff -u -r1.1 menu.c
--- dlls/user/menu.c	31 Aug 2004 01:10:08 -0000	1.1
+++ dlls/user/menu.c	5 Sep 2004 14:32:43 -0000
@@ -3555,6 +3555,29 @@
             lppop->hWnd = 0;
         }
 
+        /* Check if the menu is still in use by a window
+           (fix for bug 1486) */
+        if (lppop->hWnd && IsWindow(lppop->hWnd) &&
+            GetMenu(lppop->hWnd) == hMenu)
+        {
+            /* Handle this situation in the same way as Windows 9x.
+               
+               Windows 9x destroys the menu and sets the window's
+               menu handle to NULL, without repainting the menu bar.
+               The application has to call SetMenu or DrawMenuBar
+               afterwards.
+
+               FIXME: Windows 2000 returns TRUE, but doesn't destroy
+                      the menu immediately. It waits until the menu
+                      is not used anymore. */
+
+            WARN("The menu %p is still in use by window %p\n",
+                  hMenu, lppop->hWnd);
+
+            MENU_SetMenu(lppop->hWnd, NULL);
+            lppop->hWnd = 0;
+        }
+
         if (lppop->items) /* recursively destroy submenus */
         {
             int i;


More information about the wine-patches mailing list