diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index 6d92b0d..2de1ca9 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -2079,6 +2079,126 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) } } } + else if (!strncmp(line + 1, "pin_tiles", 9)) + { + BOOL bFirst = TRUE; + DWORD dwPermitOldStartTileData = TRUE; + DWORD dwSize = sizeof(DWORD); + RegSetKeyValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot", REG_DWORD, &dwPermitOldStartTileData, dwSize); + /* + LPCWSTR csPath = L"::{26EE0668-A00A-44D7-9371-BEB064C98683}"; + SFGAOF stSFGAOFIn = 0; + SFGAOF stSFGAOFOut = 0; + SHParseDisplayName(csPath, NULL, &pidl, stSFGAOFIn, &stSFGAOFOut); + */ + WCHAR wszOrigPath[MAX_PATH], wszCurPath[MAX_PATH]; + IShellFolder* psfDesktop = NULL; + hr = SHGetDesktopFolder(&psfDesktop); + if (psfDesktop) + { + LPITEMIDLIST pidl; + hr = SHGetFolderLocation(NULL, CSIDL_CONTROLS, (HANDLE)-1, 0, &pidl); + if (pidl) + { + STRRET strret; + hr = psfDesktop->lpVtbl->GetDisplayNameOf(psfDesktop, pidl, SHGDN_FORPARSING, &strret); + StrRetToBufW(&strret, pidl, wszOrigPath, MAX_PATH); + SHOpenFolderAndSelectItems(pidl, 0, NULL, 0); + VARIANT vt; + HRESULT hr = E_FAIL; + IShellWindows* pShellWindows = NULL; + hr = CoCreateInstance(&CLSID_ShellWindows, NULL, CLSCTX_ALL, &IID_IShellWindows, &pShellWindows); + if (pShellWindows) + { + long k = 0; + pShellWindows->lpVtbl->get_Count(pShellWindows, &k); + for (int i = 0; i < k; ++i) + { + vt.vt = VT_I4; + vt.intVal = i; + IDispatch* pDispatch = NULL; + hr = pShellWindows->lpVtbl->Item(pShellWindows, vt, &pDispatch); + if (pDispatch) + { + IWebBrowserApp* pWebBrowserApp = NULL; + hr = pDispatch->lpVtbl->QueryInterface(pDispatch, &IID_IWebBrowserApp, &pWebBrowserApp); + if (pWebBrowserApp) + { + IServiceProvider* pServiceProvider = NULL; + hr = pWebBrowserApp->lpVtbl->QueryInterface(pWebBrowserApp, &IID_IServiceProvider, &pServiceProvider); + if (pServiceProvider) + { + IShellBrowser* pShellBrowser = NULL; + hr = pServiceProvider->lpVtbl->QueryService(pServiceProvider, &SID_STopLevelBrowser, &IID_IShellBrowser, &pShellBrowser); + if (pShellBrowser) + { + IShellView* pShellView = NULL; + hr = pShellBrowser->lpVtbl->QueryActiveShellView(pShellBrowser, &pShellView); + if (pShellView) + { + IFolderView* pFolderView = NULL; + hr = pShellView->lpVtbl->QueryInterface(pShellView, &IID_IFolderView, &pFolderView); + if (pFolderView) + { + IPersistFolder2* pPersistFolder2 = NULL; + hr = pFolderView->lpVtbl->GetFolder(pFolderView, &IID_IPersistFolder2, &pPersistFolder2); + if (pPersistFolder2) + { + LPITEMIDLIST pCur = NULL; + hr = pPersistFolder2->lpVtbl->GetCurFolder(pPersistFolder2, &pCur); + if (pCur) + { + hr = psfDesktop->lpVtbl->GetDisplayNameOf(psfDesktop, pCur, SHGDN_FORPARSING, &strret); + StrRetToBufW(&strret, pidl, wszCurPath, MAX_PATH); + if (!_wcsnicmp(wszOrigPath, wszCurPath, 40) && wcslen(wszCurPath) == 40 && bFirst) + { + LPITEMIDLIST pNew = NULL; + hr = SHGetFolderLocation(NULL, CSIDL_DRIVES, (HANDLE)-1, 0, &pNew); + if (pNew) + { + hr = pShellBrowser->lpVtbl->BrowseObject(pShellBrowser, pNew, SBSP_SAMEBROWSER); + if (SUCCEEDED(hr)) + { + HWND hWndExp = NULL; + pWebBrowserApp->lpVtbl->get_HWND(pWebBrowserApp, &hWndExp); + if (hWndExp) + { + INPUT input; + ZeroMemory(&input, sizeof(INPUT)); + input.type = INPUT_KEYBOARD; + input.ki.wVk = VK_F5; + SetForegroundWindow(hWndExp); + SendInput(1, &input, sizeof(INPUT)); + bFirst = FALSE; + } + } + CoTaskMemFree(pNew); + } + } + CoTaskMemFree(pCur); + } + pPersistFolder2->lpVtbl->Release(pPersistFolder2); + } + pFolderView->lpVtbl->Release(pFolderView); + } + pShellView->lpVtbl->Release(pShellView); + } + pShellBrowser->lpVtbl->Release(pShellBrowser); + } + pServiceProvider->lpVtbl->Release(pServiceProvider); + } + pWebBrowserApp->lpVtbl->Release(pWebBrowserApp); + } + pDispatch->lpVtbl->Release(pDispatch); + } + } + pShellWindows->lpVtbl->Release(pShellWindows); + } + CoTaskMemFree(pidl); + } + psfDesktop->lpVtbl->Release(psfDesktop); + } + } } } dwMaxHeight += dwLineHeight * dy; diff --git a/ExplorerPatcher/GUI.h b/ExplorerPatcher/GUI.h index c954f66..333f7ec 100644 --- a/ExplorerPatcher/GUI.h +++ b/ExplorerPatcher/GUI.h @@ -25,6 +25,8 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #include "fmemopen.h" #include "utility.h" #include "../ep_weather_host/ep_weather.h" +#include +#include #define MAX_LINE_LENGTH 2000 extern HMODULE hModule; diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index f49e572..d3e1705 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -8152,25 +8152,49 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall) } } + DWORD dwPermitOldStartTileData = FALSE; + DWORD dwSize = sizeof(DWORD); if (bInstall) { - DWORD dwSize = sizeof(DWORD); + dwSize = sizeof(DWORD); RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"Start_ShowClassicMode", RRF_RT_DWORD, NULL, &dwStartShowClassicMode, &dwSize); + dwSize = sizeof(DWORD); + RegGetValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot", RRF_RT_DWORD, NULL, &dwPermitOldStartTileData, &dwSize); } - if (dwStartShowClassicMode) + if (dwStartShowClassicMode && dwPermitOldStartTileData) { HANDLE hCombase = LoadLibraryW(L"combase.dll"); if (hCombase) { if (bInstall) { - VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", patched_LoadLibraryExW); - } - else - { - VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", LoadLibraryExW); - FreeLibrary(hCombase); - FreeLibrary(hCombase); + WCHAR wszPath[MAX_PATH], wszExpectedPath[MAX_PATH]; + ZeroMemory(wszPath, MAX_PATH); + ZeroMemory(wszExpectedPath, MAX_PATH); + DWORD dwLength = MAX_PATH; + HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()); + if (hProcess) + { + QueryFullProcessImageNameW(hProcess, 0, wszPath, &dwLength); + CloseHandle(hProcess); + } + if (GetWindowsDirectoryW(wszExpectedPath, MAX_PATH)) + { + wcscat_s(wszExpectedPath, MAX_PATH, L"\\explorer.exe"); + if (!_wcsicmp(wszPath, wszExpectedPath)) + { + dwPermitOldStartTileData = FALSE; + dwSize = sizeof(DWORD); + RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot"); + VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", patched_LoadLibraryExW); + } + } + else + { + VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", LoadLibraryExW); + FreeLibrary(hCombase); + FreeLibrary(hCombase); + } } } } diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index ade5a74..d13ffb1 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -260,6 +260,9 @@ ;x 3 Hide ;x 1 Disable ;"Virtualized_{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}_NoStartMenuMorePrograms"=dword:00000000 +;u Pin tiles to Windows 10 Start menu from File Explorer +;pin_tiles + ;T Window switcher