From f12b70addb66d683ebdb73b7fb334017a1cfe36a Mon Sep 17 00:00:00 2001 From: Guy Albertelli Date: Thu, 11 May 2000 00:06:11 +0000 Subject: [PATCH] Revalidate menu handle in mt.hTopMenu after DispatchMessage. --- controls/menu.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/controls/menu.c b/controls/menu.c index 979170443b9..afade7e2a26 100644 --- a/controls/menu.c +++ b/controls/menu.c @@ -2907,24 +2907,31 @@ static INT MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y, ReleaseCapture(); - menu = MENU_GetMenu( mt.hTopMenu ); - - if( IsWindow( mt.hOwnerWnd ) ) + /* If dropdown is still painted and the close box is clicked on + then the menu will be destroyed as part of the DispatchMessage above. + This will then invalidate the menu handle in mt.hTopMenu. We should + check for this first. */ + if( IsMenu( mt.hTopMenu ) ) { - MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE ); + menu = MENU_GetMenu( mt.hTopMenu ); - if (menu && menu->wFlags & MF_POPUP) - { - ShowWindow( menu->hWnd, SW_HIDE ); - uSubPWndLevel = 0; - } - MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 ); - SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 ); + if( IsWindow( mt.hOwnerWnd ) ) + { + MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE ); + + if (menu && menu->wFlags & MF_POPUP) + { + ShowWindow( menu->hWnd, SW_HIDE ); + uSubPWndLevel = 0; + } + MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 ); + SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 ); + } + + /* Reset the variable for hiding menu */ + if( menu ) menu->bTimeToHide = FALSE; } - /* Reset the variable for hiding menu */ - menu->bTimeToHide = FALSE; - /* The return value is only used by TrackPopupMenu */ return ((executedMenuId != -1) ? executedMenuId : 0); }