From 96d86fca58a6678fea7fcb15b3c7c2e217a8eb7a Mon Sep 17 00:00:00 2001 From: David Quintana Date: Thu, 4 Dec 2014 19:53:02 +0000 Subject: [PATCH] [EXPLORER] * Reorganize a bit the CTrayWindowCtxMenu::QueryContextMenu method and do not error if AddContextMenus fails. Fixes the taskbar context menu not opening on right-click. (No need to call it explorer-new now that it's the primary one!) CORE-8838 svn path=/trunk/; revision=65560 --- reactos/base/shell/explorer/tbsite.cpp | 16 ++--- reactos/base/shell/explorer/traywnd.cpp | 92 ++++++++++++------------- 2 files changed, 50 insertions(+), 58 deletions(-) diff --git a/reactos/base/shell/explorer/tbsite.cpp b/reactos/base/shell/explorer/tbsite.cpp index 74041de90e0..c5924564a63 100644 --- a/reactos/base/shell/explorer/tbsite.cpp +++ b/reactos/base/shell/explorer/tbsite.cpp @@ -288,11 +288,11 @@ public: IN UINT uFlags, OUT IContextMenu **ppcm) { - IShellService *pSs; - HRESULT hRet; - if (ContextMenu == NULL) { + HRESULT hRet; + CComPtr pSs; + /* Cache the context menu so we don't need to CoCreateInstance all the time... */ hRet = CoCreateInstance(CLSID_BandSiteMenu, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellService, &pSs)); TRACE("CoCreateInstance(CLSID_BandSiteMenu) for IShellService returned: 0x%x\n", hRet); @@ -302,14 +302,11 @@ public: hRet = pSs->SetOwner((IBandSite*)this); if (!SUCCEEDED(hRet)) { - pSs->Release(); return hRet; } hRet = pSs->QueryInterface(IID_PPV_ARG(IContextMenu, &ContextMenu)); - pSs->Release(); - if (!SUCCEEDED(hRet)) return hRet; } @@ -321,12 +318,7 @@ public: } /* Add the menu items */ - return ContextMenu->QueryContextMenu( - hmenu, - indexMenu, - idCmdFirst, - idCmdLast, - uFlags); + return ContextMenu->QueryContextMenu(hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags); } virtual HRESULT STDMETHODCALLTYPE Lock( diff --git a/reactos/base/shell/explorer/traywnd.cpp b/reactos/base/shell/explorer/traywnd.cpp index 79f58e5f327..74a90680bbb 100644 --- a/reactos/base/shell/explorer/traywnd.cpp +++ b/reactos/base/shell/explorer/traywnd.cpp @@ -3029,59 +3029,59 @@ public: { HMENU menubase = LoadPopupMenu(hExplorerInstance, MAKEINTRESOURCE(IDM_TRAYWND)); - if (menubase) + if (!menubase) + return HRESULT_FROM_WIN32(GetLastError()); + + int count = ::GetMenuItemCount(menubase); + + for (int i = 0; i < count; i++) { - int count = ::GetMenuItemCount(menubase); + WCHAR label[128]; - for (int i = 0; i < count; i++) - { - WCHAR label[128]; + MENUITEMINFOW mii = { 0 }; + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS + | MIIM_DATA | MIIM_STRING | MIIM_BITMAP | MIIM_FTYPE; + mii.dwTypeData = label; + mii.cch = _countof(label); + ::GetMenuItemInfoW(menubase, i, TRUE, &mii); - MENUITEMINFOW mii = { 0 }; - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS - | MIIM_DATA | MIIM_STRING | MIIM_BITMAP | MIIM_FTYPE; - mii.dwTypeData = label; - mii.cch = _countof(label); - ::GetMenuItemInfoW(menubase, i, TRUE, &mii); + TRACE("Adding item %d label %S type %d\n", mii.wID, mii.dwTypeData, mii.fType); - TRACE("Adding item %d label %S type %d\n", mii.wID, mii.dwTypeData, mii.fType); - - mii.fType |= MFT_RADIOCHECK; - - ::InsertMenuItemW(hPopup, i + 1, TRUE, &mii); - } - - ::DestroyMenu(menubase); - - if (SHRestricted(REST_CLASSICSHELL) != 0) - { - DeleteMenu(hPopup, - ID_LOCKTASKBAR, - MF_BYCOMMAND); - } - - CheckMenuItem(hPopup, - ID_LOCKTASKBAR, - MF_BYCOMMAND | (TrayWnd->Locked ? MF_CHECKED : MF_UNCHECKED)); - - if (TrayWnd->TrayBandSite != NULL) - { - if (SUCCEEDED(TrayWnd->TrayBandSite->AddContextMenus( - hPopup, - 0, - ID_SHELL_CMD_FIRST, - ID_SHELL_CMD_LAST, - CMF_NORMAL, - &pcm))) - { - return S_OK; - } - } + mii.fType |= MFT_RADIOCHECK; + ::InsertMenuItemW(hPopup, i + 1, TRUE, &mii); } - return E_FAIL; + ::DestroyMenu(menubase); + + if (SHRestricted(REST_CLASSICSHELL) != 0) + { + DeleteMenu(hPopup, + ID_LOCKTASKBAR, + MF_BYCOMMAND); + } + + CheckMenuItem(hPopup, + ID_LOCKTASKBAR, + MF_BYCOMMAND | (TrayWnd->Locked ? MF_CHECKED : MF_UNCHECKED)); + + if (TrayWnd->TrayBandSite != NULL) + { + if (FAILED(TrayWnd->TrayBandSite->AddContextMenus( + hPopup, + 0, + ID_SHELL_CMD_FIRST, + ID_SHELL_CMD_LAST, + CMF_NORMAL, + &pcm))) + { + WARN("AddContextMenus failed.\n"); + pcm = NULL; + } + } + + return S_OK; } virtual HRESULT STDMETHODCALLTYPE