From 87a2638fb1a9e3c33c6985ca20b978665dd61a69 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Thu, 26 May 2022 18:11:08 +0300 Subject: [PATCH] Spotlight: Fixed a bug that had Spotlight context menu entries appear in some menus other than the desktop context menu --- ExplorerPatcher/dllmain.c | 11 +++++++---- ExplorerPatcher/utility.c | 33 ++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 3e17d34..f67e274 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -9183,6 +9183,7 @@ BOOL SHELL32_CanDisplayWin8CopyDialogHook() HKEY hKeySpotlight1 = NULL; HKEY hKeySpotlight2 = NULL; +BOOL bSpotlightIsDesktopContextMenu = FALSE; LSTATUS shell32_RegCreateKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions, REGSAM samDesired, const LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition) { @@ -9216,15 +9217,17 @@ LSTATUS shell32_RegSetValueExW(HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, D BOOL shell32_DeleteMenu(HMENU hMenu, UINT uPosition, UINT uFlags) { - if (uPosition == 0x7053 && IsSpotlightEnabled() && dwSpotlightDesktopMenuMask) - { - SpotlightHelper(dwSpotlightDesktopMenuMask, GetDesktopWindow(), hMenu, NULL); - } + if (uPosition == 0x7053 && IsSpotlightEnabled() && dwSpotlightDesktopMenuMask) bSpotlightIsDesktopContextMenu = TRUE; return DeleteMenu(hMenu, uPosition, uFlags); } BOOL shell32_TrackPopupMenu(HMENU hMenu, UINT uFlags, int x, int y, int nReserved, HWND hWnd, const RECT* prcRect) { + if (IsSpotlightEnabled() && dwSpotlightDesktopMenuMask && RegisterWindowMessageW(L"WorkerW") == GetClassWord(GetParent(hWnd), GCW_ATOM) && bSpotlightIsDesktopContextMenu) + { + SpotlightHelper(dwSpotlightDesktopMenuMask, hWnd, hMenu, NULL); + } + bSpotlightIsDesktopContextMenu = FALSE; BOOL bRet = TrackPopupMenuHook(hMenu, uFlags, x, y, nReserved, hWnd, prcRect); if (IsSpotlightEnabled() && dwSpotlightDesktopMenuMask) { diff --git a/ExplorerPatcher/utility.c b/ExplorerPatcher/utility.c index 541babd..7ed2506 100644 --- a/ExplorerPatcher/utility.c +++ b/ExplorerPatcher/utility.c @@ -1519,7 +1519,7 @@ void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt) else if (!(dwOp & ~SPOP_INSERTMENU_ALL)) { MENUITEMINFOW mii; - int i = -1; + int i = ARRAYSIZE(spop_insertmenu_ops) - 1; while (1) { if (i == -1 ? ((dwOp & SPOP_INSERTMENU_INFOTIP1) || (dwOp & SPOP_INSERTMENU_INFOTIP2)) : (dwOp & spop_insertmenu_ops[i])) @@ -1548,28 +1548,31 @@ void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt) { if (i == -1) { + WCHAR* pCInit = mii.dwTypeData; WCHAR* pC = wcschr(mii.dwTypeData, L'\r'); if (pC) { pC[0] = 0; + pC++; + WCHAR* pC2 = wcschr(pC, L'\r'); + if (pC2) + { + pC2[0] = 0; + } + mii.dwTypeData = pC; + mii.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA | MIIM_STATE; mii.wID = 3999 + i - 1; mii.dwItemData = SPOP_CLICKMENU_FIRST + i - 1; mii.fType = MFT_STRING; mii.fState = MFS_DISABLED; - if (dwOp & SPOP_INSERTMENU_INFOTIP1) + if (dwOp & SPOP_INSERTMENU_INFOTIP2) { - InsertMenuItemW(hMenu, GetMenuItemCount(hMenu) - 1, TRUE, &mii); + InsertMenuItemW(hMenu, 3, TRUE, &mii); } - pC++; - WCHAR* pC2 = wcschr(pC, L'\r'); - if (pC2) - { - pC2[0] = 0; - } - mii.dwTypeData = pC; + mii.dwTypeData = pCInit; } } mii.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA | (i == -1 ? MIIM_STATE : 0); @@ -1577,22 +1580,22 @@ void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt) mii.dwItemData = SPOP_CLICKMENU_FIRST + i; mii.fType = MFT_STRING; if (i == -1) mii.fState = MFS_DISABLED; - if (i != -1 || (i == -1 && (dwOp & SPOP_INSERTMENU_INFOTIP2))) + if (i != -1 || (i == -1 && (dwOp & SPOP_INSERTMENU_INFOTIP1))) { - InsertMenuItemW(hMenu, GetMenuItemCount(hMenu) - 1, TRUE, &mii); + InsertMenuItemW(hMenu, 3, TRUE, &mii); } } free(buf); } } } - i++; - if (i >= ARRAYSIZE(spop_insertmenu_ops)) break; + i--; + if (i < -1) break; } mii.fMask = MIIM_FTYPE | MIIM_DATA; mii.dwItemData = 0; mii.fType = MFT_SEPARATOR; - InsertMenuItemW(hMenu, GetMenuItemCount(hMenu) - 1, TRUE, &mii); + InsertMenuItemW(hMenu, 3, TRUE, &mii); } else if (dwOp >= SPOP_CLICKMENU_FIRST && dwOp <= SPOP_CLICKMENU_LAST) {