From 5aaead3fdb1401fb68109658fa3db1e462a27008 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Tue, 12 Mar 2024 15:58:22 +0900 Subject: [PATCH] [SHELL32] Start Menu: Enhance context menu (#6606) Improve Start Menu usability. JIRA issue: CORE-19477 - Add CSIDLFromID helper function. - Return a context menu interface at CShellMenuCallback::OnGetContextMenu. FIXME: CSIDL_CONTROLS, CSIDL_NETWORK, and CSIDL_PRINTERS context menu wrongly open My Computer. --- dll/win32/shell32/shellmenu/CStartMenu.cpp | 74 ++++++++++++---------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/dll/win32/shell32/shellmenu/CStartMenu.cpp b/dll/win32/shell32/shellmenu/CStartMenu.cpp index f2975ee28b5..218f18919a2 100644 --- a/dll/win32/shell32/shellmenu/CStartMenu.cpp +++ b/dll/win32/shell32/shellmenu/CStartMenu.cpp @@ -292,8 +292,13 @@ private: break; } case IDM_FAVORITES: + case IDM_MYDOCUMENTS: + case IDM_MYPICTURES: + case IDM_CONTROLPANEL: + case IDM_NETWORKCONNECTIONS: + case IDM_PRINTERSANDFAXES: { - hr = AddStartMenuItems(pShellMenu, CSIDL_FAVORITES, SMSET_TOP); + hr = AddStartMenuItems(pShellMenu, CSIDLFromID(psmd->uId), SMSET_TOP); break; } case IDM_DOCUMENTS: @@ -309,31 +314,6 @@ private: hr = AddStartMenuItems(pShellMenu, CSIDL_RECENT, SMSET_BOTTOM); break; } - case IDM_MYDOCUMENTS: - { - hr = AddStartMenuItems(pShellMenu, CSIDL_MYDOCUMENTS, SMSET_TOP); - break; - } - case IDM_MYPICTURES: - { - hr = AddStartMenuItems(pShellMenu, CSIDL_MYPICTURES, SMSET_TOP); - break; - } - case IDM_CONTROLPANEL: - { - hr = AddStartMenuItems(pShellMenu, CSIDL_CONTROLS, SMSET_TOP); - break; - } - case IDM_NETWORKCONNECTIONS: - { - hr = AddStartMenuItems(pShellMenu, CSIDL_NETWORK, SMSET_TOP); - break; - } - case IDM_PRINTERSANDFAXES: - { - hr = AddStartMenuItems(pShellMenu, CSIDL_PRINTERS, SMSET_TOP); - break; - } case IDM_SETTINGS: { MENUITEMINFOW mii = { sizeof(mii), MIIM_SUBMENU }; @@ -367,17 +347,43 @@ private: return hr; } + INT CSIDLFromID(UINT uId) const + { + switch (uId) + { + case IDM_PROGRAMS: return CSIDL_PROGRAMS; + case IDM_FAVORITES: return CSIDL_FAVORITES; + case IDM_DOCUMENTS: return CSIDL_RECENT; + case IDM_MYDOCUMENTS: return CSIDL_MYDOCUMENTS; + case IDM_MYPICTURES: return CSIDL_MYPICTURES; + case IDM_CONTROLPANEL: return CSIDL_CONTROLS; + case IDM_NETWORKCONNECTIONS: return CSIDL_NETWORK; + case IDM_PRINTERSANDFAXES: return CSIDL_PRINTERS; + default: return 0; + } + } + HRESULT OnGetContextMenu(LPSMDATA psmd, REFIID iid, void ** pv) { - if (psmd->uId == IDM_PROGRAMS || - psmd->uId == IDM_CONTROLPANEL || - psmd->uId == IDM_NETWORKCONNECTIONS || - psmd->uId == IDM_PRINTERSANDFAXES) - { - //UNIMPLEMENTED - } + INT csidl = CSIDLFromID(psmd->uId); + if (!csidl) + return S_FALSE; - return S_FALSE; + TRACE("csidl: 0x%X\n", csidl); + + if (csidl == CSIDL_CONTROLS || csidl == CSIDL_NETWORK || csidl == CSIDL_PRINTERS) + FIXME("This CSIDL %d wrongly opens My Computer. CORE-19477\n", csidl); + + CComHeapPtr pidl; + SHGetSpecialFolderLocation(NULL, csidl, &pidl); + + CComPtr pSF; + LPCITEMIDLIST pidlChild = NULL; + HRESULT hr = SHBindToParent(pidl, IID_IShellFolder, (void**)&pSF, &pidlChild); + if (FAILED(hr)) + return hr; + + return pSF->GetUIObjectOf(NULL, 1, &pidlChild, IID_IContextMenu, NULL, pv); } HRESULT OnGetObject(LPSMDATA psmd, REFIID iid, void ** pv)