Patch for bug 1848 (3rd repost) - TrackPopupMenu returns wrong result, when menu is canceled

Andreas Rosenberg sonix2003 at ctf-z.de
Mon Feb 9 12:54:21 CST 2004


I've posted this in mid December and end of January - but it wasn't included in the release branch.
Dimitrie asked me to resend the patch a third time. 

A fix for the wrong results of TrackPopupMenu when clicking outside a popup menu. 
I compared the results with Windows and my patch and it seems ok, 
except for the behavior of "GetLastError", when passing wrong parameters. 
I assume the "MENU_GetMenu" case could be ok,
but somebody should look at the "WIN_GetFullHandle" case too.

This is a diff to CVS from 01/30/2004.

? diff-menu
? patch.diff
? libs/uuid/Makefile
? programs/regedit/folder1.bmp
? programs/regedit/folder2.bmp
? programs/regedit/folder3.bmp
Index: controls/menu.c
===================================================================
RCS file: /home/wine/wine/controls/menu.c,v
retrieving revision 1.173
diff -u -r1.173 menu.c
--- controls/menu.c	27 Jan 2004 00:01:44 -0000	1.173
+++ controls/menu.c	30 Jan 2004 19:30:27 -0000
@@ -2652,6 +2652,10 @@
     mt.trackFlags = 0;
     mt.hCurrentMenu = hmenu;
     mt.hTopMenu = hmenu;
+    /* What happens if an invalid window handle is being passed? I tried to find out what's
+    going on in such a case, but I know to little about communication with the wine server.
+    Somebody who might know about this, please add a test and return FALSE here with a
+    SetLastError(ERROR_INVALID_WINDOW_HANDLE);*/
     mt.hOwnerWnd = WIN_GetFullHandle( hwnd );
     mt.pt.x = x;
     mt.pt.y = y;
@@ -2661,7 +2665,11 @@
           (lprect) ? lprect->right : 0,  (lprect) ? lprect->bottom : 0);
 
     fEndMenu = FALSE;
-    if (!(menu = MENU_GetMenu( hmenu ))) return FALSE;
+    if (!(menu = MENU_GetMenu( hmenu )))
+    {
+        SetLastError(ERROR_INVALID_MENU_HANDLE);
+        return FALSE;
+    }
 
     if (wFlags & TPM_BUTTONDOWN)
     {
@@ -2926,7 +2934,7 @@
     }
 
     /* The return value is only used by TrackPopupMenu */
-    return ((executedMenuId != -1) ? executedMenuId : 0);
+    return (executedMenuId);
 }
 
 /***********************************************************************
@@ -3073,11 +3081,16 @@
         SendMessageW( hWnd, WM_INITMENUPOPUP, (WPARAM)hMenu, 0);
 
     if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
+        /* -1 is returned by MENU_TrackMenu when the menu was canceled */
 	ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
     MENU_ExitTracking(hWnd);
 
-    if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
-	ret = 1;
+    if (ret < 0)
+        if (wFlags & TPM_RETURNCMD) ret = 0;
+        else ret = 1;
+    else
+        if ((!(wFlags & TPM_RETURNCMD)) && (ret > 0))
+            ret = 1;
 
     return ret;
 }




More information about the wine-patches mailing list