From: Andrew Eikum aeikum@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/user32/menu.c | 174 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 76 deletions(-)
diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c index 71bd5dd51a..f5176fdeca 100644 --- a/dlls/user32/menu.c +++ b/dlls/user32/menu.c @@ -565,17 +565,19 @@ static UINT MENU_GetStartOfPrevColumn( /*********************************************************************** * MENU_FindItem * - * Find a menu item. Return a pointer on the item, and modifies *hmenu + * Find a menu item. Return a pointer on the item, and modifies *pmenu * in case the item was in a sub-menu. */ -static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags ) +static MENUITEM *MENU_FindItem( POPUPMENU **pmenu, UINT *nPos, UINT wFlags ) { - POPUPMENU *menu; + POPUPMENU *menu = *pmenu; MENUITEM *fallback = NULL; UINT fallback_pos = 0; UINT i;
- if ((*hmenu == (HMENU)0xffff) || (!(menu = MENU_GetMenu(*hmenu)))) return NULL; + if (!menu) + return NULL; + if (wFlags & MF_BYPOSITION) { if (*nPos >= menu->nItems) return NULL; @@ -588,11 +590,11 @@ static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags ) { if (item->fType & MF_POPUP) { - HMENU hsubmenu = item->hSubMenu; - MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags ); + POPUPMENU *submenu = MENU_GetMenu(item->hSubMenu); + MENUITEM *subitem = MENU_FindItem( &submenu, nPos, wFlags ); if (subitem) { - *hmenu = hsubmenu; + *pmenu = submenu; return subitem; } else if (item->wID == *nPos) @@ -623,25 +625,27 @@ static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags ) * *hmenu in case it is found in another sub-menu. * If the submenu cannot be found, NO_SELECTED_ITEM is returned. */ -static UINT MENU_FindSubMenu( HMENU *hmenu, HMENU hSubTarget ) +static UINT MENU_FindSubMenu( POPUPMENU **pmenu, POPUPMENU *subTarget ) { - POPUPMENU *menu; + POPUPMENU *menu = *pmenu; UINT i; MENUITEM *item; - if (((*hmenu)==(HMENU)0xffff) || - (!(menu = MENU_GetMenu(*hmenu)))) + + if (!menu) return NO_SELECTED_ITEM; + item = menu->items; for (i = 0; i < menu->nItems; i++, item++) { if(!(item->fType & MF_POPUP)) continue; - if (item->hSubMenu == hSubTarget) { + if (item->hSubMenu == MENU_GetHandle(subTarget)) + { return i; } else { - HMENU hsubmenu = item->hSubMenu; - UINT pos = MENU_FindSubMenu( &hsubmenu, hSubTarget ); + POPUPMENU *submenu = MENU_GetMenu(item->hSubMenu); + UINT pos = MENU_FindSubMenu( &submenu, subTarget ); if (pos != NO_SELECTED_ITEM) { - *hmenu = hsubmenu; + *pmenu = submenu; return pos; } } @@ -750,16 +754,16 @@ static enum hittest MENU_FindItemByCoords( const POPUPMENU *menu, POINT pt, UINT * Find the menu item selected by a key press. * Return item id, -1 if none, -2 if we should close the menu. */ -static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu, +static UINT MENU_FindItemByKey( HWND hwndOwner, POPUPMENU *menu, WCHAR key, BOOL forceMenuChar ) { - TRACE("\tlooking for '%c' (0x%02x) in [%p]\n", (char)key, key, hmenu ); + TRACE("\tlooking for '%c' (0x%02x) in [%p]\n", (char)key, key, menu );
- if (!IsMenu( hmenu )) hmenu = GetSubMenu( get_win_sys_menu(hwndOwner), 0); + if (!menu) + menu = MENU_GetMenu(GetSubMenu( get_win_sys_menu(hwndOwner), 0));
- if (hmenu) + if (menu) { - POPUPMENU *menu = MENU_GetMenu( hmenu ); MENUITEM *item = menu->items; LRESULT menuchar;
@@ -785,7 +789,7 @@ static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu, } } menuchar = SendMessageW( hwndOwner, WM_MENUCHAR, - MAKEWPARAM( key, menu->wFlags ), (LPARAM)hmenu ); + MAKEWPARAM( key, menu->wFlags ), (LPARAM)MENU_GetHandle(menu) ); if (HIWORD(menuchar) == MNC_EXECUTE) return LOWORD(menuchar); if (HIWORD(menuchar) == MNC_CLOSE) return (UINT)(-2); } @@ -2005,7 +2009,7 @@ MENU_EnsureMenuItemVisible(LPPOPUPMENU lppop, UINT wIndex, HDC hdc) * MENU_SelectItem */ static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex, - BOOL sendMenuSelect, HMENU topmenu ) + BOOL sendMenuSelect, HMENU htopmenu ) { LPPOPUPMENU lppop; HDC hdc; @@ -2053,14 +2057,17 @@ static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex, } } else if (sendMenuSelect) { - if(topmenu){ + POPUPMENU *topmenu; + + if (htopmenu && (topmenu = MENU_GetMenu(htopmenu))) + { int pos; - if((pos=MENU_FindSubMenu(&topmenu, hmenu))!=NO_SELECTED_ITEM){ - POPUPMENU *ptm = MENU_GetMenu( topmenu ); - MENUITEM *ip = &ptm->items[pos]; + if ((pos=MENU_FindSubMenu(&topmenu, lppop)) != NO_SELECTED_ITEM) + { + MENUITEM *ip = &topmenu->items[pos]; SendMessageW( hwndOwner, WM_MENUSELECT, MAKEWPARAM(pos, ip->fType | ip->fState | - (ptm->wFlags & MF_SYSMENU)), (LPARAM)topmenu); + (topmenu->wFlags & MF_SYSMENU)), (LPARAM)htopmenu); } } } @@ -2126,7 +2133,7 @@ static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags ) if (pos > menu->nItems) pos = menu->nItems; } else { - if (!MENU_FindItem( &hMenu, &pos, flags )) + if (!MENU_FindItem( &menu, &pos, flags )) pos = menu->nItems; else { if (!(menu = MENU_GetMenu( hMenu ))) @@ -3258,7 +3265,7 @@ static BOOL MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y, /* We will find a better way real soon... */ if (msg.wParam < 32) break;
- pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu, + pos = MENU_FindItemByKey( mt.hOwnerWnd, MENU_GetMenu(mt.hCurrentMenu), LOWORD(msg.wParam), FALSE ); if (pos == (UINT)-2) fEndMenu = TRUE; else if (pos == (UINT)-1) MessageBeep(0); @@ -3444,7 +3451,7 @@ void MENU_TrackKbdMenuBar( HWND hwnd, UINT wParam, WCHAR wChar)
if( wChar && wChar != ' ' ) { - uItem = MENU_FindItemByKey( hwnd, hTrackMenu, wChar, (wParam & HTSYSMENU) ); + uItem = MENU_FindItemByKey( hwnd, MENU_GetMenu(hTrackMenu), wChar, (wParam & HTSYSMENU) ); if ( uItem >= (UINT)(-2) ) { if( uItem == (UINT)(-1) ) MessageBeep(0); @@ -3681,10 +3688,11 @@ BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data, */ DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags ) { + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM *item; DWORD ret;
- if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1; + if (!(item = MENU_FindItem( &menu, &id, flags ))) return -1; ret = item->fState & MF_CHECKED; if (flags & MF_CHECKED) item->fState |= MF_CHECKED; else item->fState &= ~MF_CHECKED; @@ -3707,7 +3715,7 @@ BOOL WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags ) if (!(menu = MENU_GetMenu(hMenu))) return (UINT)-1;
- if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) + if (!(item = MENU_FindItem( &menu, &wItemID, wFlags ))) return (UINT)-1;
oldflags = item->fState & (MF_GRAYED | MF_DISABLED); @@ -3745,12 +3753,14 @@ INT WINAPI GetMenuStringA( LPSTR str, /* [out] outbuffer. If NULL, func returns entry length*/ INT nMaxSiz, /* [in] length of buffer. if 0, func returns entry len*/ UINT wFlags /* [in] MF_ flags */ -) { +) +{ + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM *item;
TRACE("menu=%p item=%04x ptr=%p len=%d flags=%04x\n", hMenu, wItemID, str, nMaxSiz, wFlags ); if (str && nMaxSiz) str[0] = '\0'; - if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) { + if (!(item = MENU_FindItem( &menu, &wItemID, wFlags ))) { SetLastError( ERROR_MENU_ITEM_NOT_FOUND); return 0; } @@ -3769,11 +3779,12 @@ INT WINAPI GetMenuStringA( INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID, LPWSTR str, INT nMaxSiz, UINT wFlags ) { + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM *item;
TRACE("menu=%p item=%04x ptr=%p len=%d flags=%04x\n", hMenu, wItemID, str, nMaxSiz, wFlags ); if (str && nMaxSiz) str[0] = '\0'; - if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) { + if (!(item = MENU_FindItem( &menu, &wItemID, wFlags ))) { SetLastError( ERROR_MENU_ITEM_NOT_FOUND); return 0; } @@ -3794,13 +3805,15 @@ INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID, BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID, UINT wHilite ) { - LPPOPUPMENU menu; - TRACE("(%p, %p, %04x, %04x);\n", hWnd, hMenu, wItemID, wHilite); - if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE; - if (!(menu = MENU_GetMenu(hMenu))) return FALSE; + POPUPMENU *menu = MENU_GetMenu(hMenu); + MENUITEM *item; + + TRACE("(%p, %p, %04x, %04x)\n", hWnd, hMenu, wItemID, wHilite); + + if (!(item = MENU_FindItem( &menu, &wItemID, wHilite ))) return FALSE; if (menu->FocusedItem == wItemID) return TRUE; MENU_HideSubPopups( hWnd, menu, FALSE, 0 ); - MENU_SelectItem( hWnd, hMenu, wItemID, TRUE, 0 ); + MENU_SelectItem( hWnd, MENU_GetHandle(menu), wItemID, TRUE, 0 ); return TRUE; }
@@ -3810,13 +3823,15 @@ BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID, */ UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags ) { + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM *item; + TRACE("(menu=%p, id=%04x, flags=%04x);\n", hMenu, wItemID, wFlags); - if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1; + if (!(item = MENU_FindItem( &menu, &wItemID, wFlags ))) return -1; debug_print_menuitem (" item: ", item, ""); if (item->fType & MF_POPUP) { - POPUPMENU *menu = MENU_GetMenu( item->hSubMenu ); + menu = MENU_GetMenu( item->hSubMenu ); if (!menu) return -1; else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff); } @@ -3847,9 +3862,10 @@ INT WINAPI GetMenuItemCount( HMENU hMenu ) */ UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos ) { + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM * lpmi;
- if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return -1; + if (!(lpmi = MENU_FindItem(&menu, (UINT *)&nPos, MF_BYPOSITION))) return -1; if (lpmi->fType & MF_POPUP) return -1; return lpmi->wID;
@@ -3976,15 +3992,14 @@ BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags, */ BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags ) { - LPPOPUPMENU menu; + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM *item;
TRACE("(menu=%p pos=%04x flags=%04x)\n",hMenu, nPos, wFlags); - if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE; - if (!(menu = MENU_GetMenu(hMenu))) return FALSE; + if (!(item = MENU_FindItem( &menu, &nPos, wFlags ))) return FALSE;
/* Remove item */ - if ((item->fType & MF_POPUP) && item->hSubMenu) + if (item->fType & MF_POPUP) MENU_ReleaseMenu(MENU_GetMenu(item->hSubMenu));
MENU_FreeItemData( item ); @@ -4016,7 +4031,8 @@ BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags ) */ BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags ) { - MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags ); + POPUPMENU *menu = MENU_GetMenu(hMenu); + MENUITEM *item = MENU_FindItem( &menu, &nPos, wFlags ); if (!item) return FALSE; if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu ); /* nPos is now the position of the item */ @@ -4031,6 +4047,7 @@ BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags ) BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags, UINT_PTR id, LPCWSTR str ) { + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM *item; MENUITEMINFOW mii;
@@ -4039,13 +4056,13 @@ BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags, else TRACE("%p %d %04x %04lx %p\n", hMenu, pos, flags, id, str );
- if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) + if (!(item = MENU_FindItem( &menu, &pos, flags ))) { /* workaround for Word 95: pretend that SC_TASKLIST item exists */ if (pos == SC_TASKLIST && !(flags & MF_BYPOSITION)) return TRUE; return FALSE; } - MENU_GetMenu(hMenu)->Height = 0; /* force size recalculate */ + menu->Height = 0; /* force size recalculation */ MENU_mnu2mnuii( flags, id, str, &mii); return SetMenuItemInfo_common( item, &mii, TRUE); } @@ -4106,9 +4123,10 @@ DWORD WINAPI GetMenuCheckMarkDimensions(void) BOOL WINAPI SetMenuItemBitmaps( HMENU hMenu, UINT nPos, UINT wFlags, HBITMAP hNewUnCheck, HBITMAP hNewCheck) { + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM *item;
- if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE; + if (!(item = MENU_FindItem( &menu, &nPos, wFlags ))) return FALSE;
if (!hNewCheck && !hNewUnCheck) { @@ -4410,9 +4428,10 @@ BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu ) */ HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos ) { + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM * lpmi;
- if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0; + if (!(lpmi = MENU_FindItem(&menu, (UINT *)&nPos, MF_BYPOSITION))) return 0; if (!(lpmi->fType & MF_POPUP)) return 0; return lpmi->hSubMenu; } @@ -4618,7 +4637,8 @@ BOOL WINAPI IsMenu(HMENU hmenu) static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos, LPMENUITEMINFOW lpmii, BOOL unicode) { - MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos ? MF_BYPOSITION : 0); + POPUPMENU *popup = MENU_GetMenu(hmenu); + MENUITEM *menu = MENU_FindItem (&popup, &item, bypos ? MF_BYPOSITION : 0);
debug_print_menuitem("GetMenuItemInfo_common: ", menu, "");
@@ -4936,6 +4956,7 @@ static BOOL MENU_NormalizeMenuItemInfoStruct( const MENUITEMINFOW *pmii_in, BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos, const MENUITEMINFOA *lpmii) { + POPUPMENU *menu = MENU_GetMenu(hmenu); MENUITEM *menuitem; MENUITEMINFOW mii;
@@ -4943,7 +4964,7 @@ BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
if (!MENU_NormalizeMenuItemInfoStruct( (const MENUITEMINFOW *)lpmii, &mii )) return FALSE;
- if (!(menuitem = MENU_FindItem( &hmenu, &item, bypos? MF_BYPOSITION : 0 ))) + if (!(menuitem = MENU_FindItem( &menu, &item, bypos? MF_BYPOSITION : 0 ))) { /* workaround for Word 95: pretend that SC_TASKLIST item exists */ if (item == SC_TASKLIST && !bypos) return TRUE; @@ -4958,13 +4979,14 @@ BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos, BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos, const MENUITEMINFOW *lpmii) { + POPUPMENU *menu = MENU_GetMenu(hmenu); MENUITEM *menuitem; MENUITEMINFOW mii;
TRACE("hmenu %p, item %u, by pos %d, info %p\n", hmenu, item, bypos, lpmii);
if (!MENU_NormalizeMenuItemInfoStruct( lpmii, &mii )) return FALSE; - if (!(menuitem = MENU_FindItem( &hmenu, &item, bypos? MF_BYPOSITION : 0 ))) + if (!(menuitem = MENU_FindItem( &menu, &item, bypos? MF_BYPOSITION : 0 ))) { /* workaround for Word 95: pretend that SC_TASKLIST item exists */ if (item == SC_TASKLIST && !bypos) return TRUE; @@ -5107,10 +5129,10 @@ BOOL WINAPI CheckMenuRadioItem(HMENU hMenu, UINT first, UINT last, UINT check, UINT bypos) { + POPUPMENU *m_first, *m_check; BOOL done = FALSE; UINT i; MENUITEM *mi_first = NULL, *mi_check; - HMENU m_first, m_check;
for (i = first; i <= last; i++) { @@ -5118,7 +5140,7 @@ BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
if (!mi_first) { - m_first = hMenu; + m_first = MENU_GetMenu(hMenu); mi_first = MENU_FindItem(&m_first, &pos, bypos); if (!mi_first) continue; mi_check = mi_first; @@ -5126,7 +5148,7 @@ BOOL WINAPI CheckMenuRadioItem(HMENU hMenu, } else { - m_check = hMenu; + m_check = MENU_GetMenu(hMenu); mi_check = MENU_FindItem(&m_check, &pos, bypos); if (!mi_check) continue; } @@ -5161,18 +5183,15 @@ BOOL WINAPI CheckMenuRadioItem(HMENU hMenu, */ BOOL WINAPI GetMenuItemRect(HWND hwnd, HMENU hMenu, UINT uItem, RECT *rect) { - POPUPMENU *menu; + POPUPMENU *menu = MENU_GetMenu(hMenu); MENUITEM *item;
TRACE("(%p,%p,%d,%p)\n", hwnd, hMenu, uItem, rect);
- item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION); + item = MENU_FindItem (&menu, &uItem, MF_BYPOSITION); if ((rect == NULL) || (item == NULL)) return FALSE;
- menu = MENU_GetMenu(hMenu); - if (!menu) return FALSE; - if (!hwnd) hwnd = menu->hWnd; if (!hwnd) return FALSE;
@@ -5384,17 +5403,20 @@ static BOOL translate_accelerator( HWND hWnd, UINT message, WPARAM wParam, LPARA mesg = 1; else { - HMENU hMenu, hSubMenu, hSysMenu; + HMENU hMenu, hSysMenu; + POPUPMENU *menu, *subMenu, *sysMenu; UINT uSysStat = (UINT)-1, uStat = (UINT)-1, nPos;
hMenu = (GetWindowLongW( hWnd, GWL_STYLE ) & WS_CHILD) ? 0 : GetMenu(hWnd); + menu = MENU_GetMenu(hMenu); hSysMenu = get_win_sys_menu( hWnd ); + sysMenu = MENU_GetMenu(hSysMenu);
/* find menu item and ask application to initialize it */ /* 1. in the system menu */ - hSubMenu = hSysMenu; + subMenu = sysMenu; nPos = cmd; - if(MENU_FindItem(&hSubMenu, &nPos, MF_BYCOMMAND)) + if (MENU_FindItem(&subMenu, &nPos, MF_BYCOMMAND)) { if (GetCapture()) mesg = 2; @@ -5403,20 +5425,20 @@ static BOOL translate_accelerator( HWND hWnd, UINT message, WPARAM wParam, LPARA else { SendMessageW(hWnd, WM_INITMENU, (WPARAM)hSysMenu, 0L); - if(hSubMenu != hSysMenu) + if (subMenu != sysMenu) { - nPos = MENU_FindSubMenu(&hSysMenu, hSubMenu); - TRACE_(accel)("hSysMenu = %p, hSubMenu = %p, nPos = %d\n", hSysMenu, hSubMenu, nPos); - SendMessageW(hWnd, WM_INITMENUPOPUP, (WPARAM)hSubMenu, MAKELPARAM(nPos, TRUE)); + nPos = MENU_FindSubMenu(&sysMenu, subMenu); + TRACE_(accel)("sysMenu = %p, subMenu = %p, nPos = %d\n", sysMenu, subMenu, nPos); + SendMessageW(hWnd, WM_INITMENUPOPUP, (WPARAM)MENU_GetHandle(subMenu), MAKELPARAM(nPos, TRUE)); } uSysStat = GetMenuState(GetSubMenu(hSysMenu, 0), cmd, MF_BYCOMMAND); } } else /* 2. in the window's menu */ { - hSubMenu = hMenu; + subMenu = menu; nPos = cmd; - if(MENU_FindItem(&hSubMenu, &nPos, MF_BYCOMMAND)) + if (MENU_FindItem(&subMenu, &nPos, MF_BYCOMMAND)) { if (GetCapture()) mesg = 2; @@ -5425,11 +5447,11 @@ static BOOL translate_accelerator( HWND hWnd, UINT message, WPARAM wParam, LPARA else { SendMessageW(hWnd, WM_INITMENU, (WPARAM)hMenu, 0L); - if(hSubMenu != hMenu) + if (subMenu != menu) { - nPos = MENU_FindSubMenu(&hMenu, hSubMenu); - TRACE_(accel)("hMenu = %p, hSubMenu = %p, nPos = %d\n", hMenu, hSubMenu, nPos); - SendMessageW(hWnd, WM_INITMENUPOPUP, (WPARAM)hSubMenu, MAKELPARAM(nPos, FALSE)); + nPos = MENU_FindSubMenu(&menu, subMenu); + TRACE_(accel)("hMenu = %p, subMenu = %p, nPos = %d\n", hMenu, subMenu, nPos); + SendMessageW(hWnd, WM_INITMENUPOPUP, (WPARAM)MENU_GetHandle(subMenu), MAKELPARAM(nPos, FALSE)); } uStat = GetMenuState(hMenu, cmd, MF_BYCOMMAND); }