Skip to content

Commit

Permalink
[SHELL32] Start Menu: Enhance context menu (#6606)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
katahiromz authored and errortek committed Mar 31, 2024
1 parent 90ebafd commit d6d1830
Showing 1 changed file with 67 additions and 8 deletions.
75 changes: 67 additions & 8 deletions dll/win32/shell32/shellmenu/CStartMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,43 @@ class CShellMenuCallback :
if (FAILED_UNEXPECTEDLY(hr))
return hr;

hr = psfDestop->BindToObject(pidlStartMenu, NULL, IID_PPV_ARG(IShellFolder, &psfStartMenu));
hr = E_FAIL;
switch (psmd->uId)
{
case IDM_PROGRAMS:
{
hr = AddStartMenuItems(pShellMenu, CSIDL_PROGRAMS, SMSET_TOP, m_psfPrograms);
break;
}
case IDM_FAVORITES:
case IDM_MYDOCUMENTS:
case IDM_MYPICTURES:
case IDM_CONTROLPANEL:
case IDM_NETWORKCONNECTIONS:
case IDM_PRINTERSANDFAXES:
{
hr = AddStartMenuItems(pShellMenu, CSIDLFromID(psmd->uId), SMSET_TOP);
break;
}
case IDM_DOCUMENTS:
{
HMENU hMenu = CreateRecentMenu();
if (hMenu == NULL)
ERR("CreateRecentMenu failed\n");

hr = pShellMenu->SetMenu(hMenu, NULL, SMSET_BOTTOM);
if (FAILED_UNEXPECTEDLY(hr))
return hr;

hr = AddStartMenuItems(pShellMenu, CSIDL_RECENT, SMSET_BOTTOM);
break;
}
case IDM_SETTINGS:
{
MENUITEMINFOW mii = { sizeof(mii), MIIM_SUBMENU };
if (GetMenuItemInfoW(psmd->hmenu, psmd->uId, FALSE, &mii))
{
UpdateSettingsMenu(mii.hSubMenu);

hr = pShellMenu->SetShellFolder(psfStartMenu, NULL, NULL, dwFlags);
if (FAILED_UNEXPECTEDLY(hr))
Expand All @@ -271,17 +304,43 @@ class CShellMenuCallback :
return pShellMenu->QueryInterface(iid, pv);
}

HRESULT OnGetContextMenu(LPSMDATA psmd, REFIID iid, void ** pv)
INT CSIDLFromID(UINT uId) const
{
if (psmd->uId == IDM_PROGRAMS ||
psmd->uId == IDM_CONTROLPANEL ||
psmd->uId == IDM_NETWORKCONNECTIONS ||
psmd->uId == IDM_PRINTERSANDFAXES)
switch (uId)
{
//UNIMPLEMENTED
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;
}
}

return S_FALSE;
HRESULT OnGetContextMenu(LPSMDATA psmd, REFIID iid, void ** pv)
{
INT csidl = CSIDLFromID(psmd->uId);
if (!csidl)
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<ITEMIDLIST> pidl;
SHGetSpecialFolderLocation(NULL, csidl, &pidl);

CComPtr<IShellFolder> 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)
Expand Down

0 comments on commit d6d1830

Please sign in to comment.