From b666d834e0e4efedbde804065392f1f0b20741f5 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Mon, 30 Aug 2021 03:48:12 +0300 Subject: [PATCH] Enables compatibility with ArchiveMenu. --- CHANGELOG.md | 4 + ExplorerPatcher/ExplorerPatcher.rc | 8 +- .../ExplorerPatcherLibrary.rc | 8 +- ExplorerPatcherLibrary/dllmain.c | 293 +++++++++++++++--- PostBuildCommand/PostBuildCommand.vcxproj | 4 +- PreBuildCommand/PreBuildCommand.vcxproj | 4 +- README.md | 2 +- 7 files changed, 269 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45dc8441e..34b71b450 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ This document includes the same release notes as in the [Releases](https://github.com/valinet/ExplorerPatcher/releases) section on GitHub. +## 22000.168.0.7 + +Enables compatibility with [ArchiveMenu](https://github.com/valinet/archivemenu). + ## 22000.168.0.6 Fixes [#5](https://github.com/valinet/ExplorerPatcher/issues/5) (removes the delay at logon on newer builds like 22000.168; the bug is similar to the effect introduced by `UndockingDisabled` on these newer builds). diff --git a/ExplorerPatcher/ExplorerPatcher.rc b/ExplorerPatcher/ExplorerPatcher.rc index a30cacca5..7afb1a0e8 100644 --- a/ExplorerPatcher/ExplorerPatcher.rc +++ b/ExplorerPatcher/ExplorerPatcher.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 22000,168,0,6 - PRODUCTVERSION 22000,168,0,6 + FILEVERSION 22000,168,0,7 + PRODUCTVERSION 22000,168,0,7 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "VALINET Solutions SRL" VALUE "FileDescription", "ExplorerPatcher Daemon" - VALUE "FileVersion", "22000.168.0.6" + VALUE "FileVersion", "22000.168.0.7" VALUE "InternalName", "ExplorerPatcher.exe" VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved." VALUE "OriginalFilename", "ExplorerPatcher.exe" VALUE "ProductName", "ExplorerPatcher" - VALUE "ProductVersion", "22000.168.0.6" + VALUE "ProductVersion", "22000.168.0.7" END END BLOCK "VarFileInfo" diff --git a/ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc b/ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc index 9972fdca1..858f799e1 100644 --- a/ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc +++ b/ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 22000,168,0,6 - PRODUCTVERSION 22000,168,0,6 + FILEVERSION 22000,168,0,7 + PRODUCTVERSION 22000,168,0,7 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "VALINET Solutions SRL" VALUE "FileDescription", "ExplorerPatcher Library" - VALUE "FileVersion", "22000.168.0.6" + VALUE "FileVersion", "22000.168.0.7" VALUE "InternalName", "ExplorerPatcherLibrary.dll" VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved." VALUE "OriginalFilename", "ExplorerPatcherLibrary.dll" VALUE "ProductName", "WinOverview" - VALUE "ProductVersion", "22000.168.0.6" + VALUE "ProductVersion", "22000.168.0.7" END END BLOCK "VarFileInfo" diff --git a/ExplorerPatcherLibrary/dllmain.c b/ExplorerPatcherLibrary/dllmain.c index 8eda31a7c..423b100b9 100644 --- a/ExplorerPatcherLibrary/dllmain.c +++ b/ExplorerPatcherLibrary/dllmain.c @@ -13,6 +13,21 @@ #include #define _LIBVALINET_INCLUDE_UNIVERSAL #include +#include +DEFINE_GUID(__uuidof_TaskbarList, + 0x56FDF344, + 0xFD6D, 0x11d0, 0x95, 0x8A, + 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90 +); +DEFINE_GUID(__uuidof_ITaskbarList, + 0x56FDF342, + 0xFD6D, 0x11d0, 0x95, 0x8A, + 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90 +); +#define OPEN_NAME L"&Open archive" +#define EXTRACT_NAME L"&Extract to \"%s\\\"" +#define OPEN_CMD L"\"C:\\Program Files\\7-Zip\\7zFM.exe\" %s" +#define EXTRACT_CMD L"\"C:\\Program Files\\7-Zip\\7zG.exe\" x -o\"%s\" -spe %s" #define APPID L"Microsoft.Windows.Explorer" #define SYMBOLS_RELATIVE_PATH "\\settings.ini" @@ -88,6 +103,8 @@ L"\r\n"; #define DEBUG #undef DEBUG +HWND archivehWnd; + funchook_t* funchook = NULL; HMODULE hModule = NULL; HWND messageWindow = NULL; @@ -362,6 +379,103 @@ LRESULT CALLBACK CLauncherTipContextMenu_WndProc( { LRESULT result; + if (uMsg == WM_COPYDATA && hWnd == archivehWnd) + { + COPYDATASTRUCT* st = lParam; + HWND srcWnd = wParam; + + POINT pt; + GetCursorPos(&pt); + + SetForegroundWindow(hWnd); + + HMENU hMenu = CreatePopupMenu(); + + TCHAR buffer[MAX_PATH + 100]; + TCHAR filename[MAX_PATH]; + ZeroMemory(filename, MAX_PATH * sizeof(TCHAR)); + memcpy(filename, st->lpData, wcslen(st->lpData) * sizeof(TCHAR)); + PathUnquoteSpacesW(filename); + PathRemoveExtensionW(filename); + PathStripPathW(filename); + wsprintf(buffer, EXTRACT_NAME, filename); + + InsertMenu(hMenu, 0, MF_BYPOSITION | MF_STRING, 1, buffer); + InsertMenu(hMenu, 0, MF_BYPOSITION | MF_STRING, 2, OPEN_NAME); + + INT64* unknown_array = calloc(4, sizeof(INT64)); + ImmersiveContextMenuHelper_ApplyOwnerDrawToMenuFunc( + hMenu, + hWnd, + &(pt), + 0xc, + unknown_array + ); + + BOOL res = TrackPopupMenu( + hMenu, + TPM_RETURNCMD, + pt.x - 15, + pt.y - 15, + 0, + hWnd, + 0 + ); + + ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenuFunc( + hMenu, + hWnd, + &(pt) + ); + free(unknown_array); + + if (res == 1 || res == 2) + { + ZeroMemory(buffer, (MAX_PATH + 100) * sizeof(TCHAR)); + if (res == 2) + { + wsprintf(buffer, OPEN_CMD, st->lpData); + //wprintf(L"%s\n%s\n\n", st->lpData, buffer); + } + else if (res == 1) + { + TCHAR path[MAX_PATH], path_orig[MAX_PATH]; + ZeroMemory(path, MAX_PATH * sizeof(TCHAR)); + ZeroMemory(path_orig, MAX_PATH * sizeof(TCHAR)); + memcpy(path, st->lpData, wcslen(st->lpData) * sizeof(TCHAR)); + memcpy(path_orig, st->lpData, wcslen(st->lpData) * sizeof(TCHAR)); + PathUnquoteSpacesW(path_orig); + PathRemoveExtensionW(path_orig); + wsprintf(buffer, EXTRACT_CMD, path_orig, path); + //wprintf(L"%s\n%s\n\n", st->lpData, buffer); + } + STARTUPINFO si = { sizeof(si) }; + PROCESS_INFORMATION pi; + BOOL b = CreateProcess( + NULL, + buffer, + NULL, + NULL, + TRUE, + CREATE_UNICODE_ENVIRONMENT, + NULL, + NULL, + &si, + &pi + ); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } + DestroyMenu(hMenu); + ShowWindow(hWnd, SW_HIDE); + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + + if (uMsg == WM_CLOSE && hWnd == archivehWnd) + { + return 0; + } + if (uMsg == WM_NCCREATE) { CREATESTRUCT* pCs = lParam; @@ -382,35 +496,41 @@ LRESULT CALLBACK CLauncherTipContextMenu_WndProc( } else { - result = 0; + result = DefWindowProc( + hWnd, + uMsg, + wParam, + lParam + ); + //result = 0; } } else { void* _this = GetWindowLongPtr(hWnd, GWLP_USERDATA); + BOOL v12 = FALSE; + if ((uMsg == WM_DRAWITEM || uMsg == WM_MEASUREITEM) && + CImmersiveContextMenuOwnerDrawHelper_s_ContextMenuWndProcFunc( + hWnd, + uMsg, + wParam, + lParam, + &v12 + )) + { + result = 0; + } + else + { + result = DefWindowProc( + hWnd, + uMsg, + wParam, + lParam + ); + } if (_this) { - BOOL v12 = FALSE; - if ((uMsg == WM_DRAWITEM || uMsg == WM_MEASUREITEM) && - CImmersiveContextMenuOwnerDrawHelper_s_ContextMenuWndProcFunc( - hWnd, - uMsg, - wParam, - lParam, - &v12 - )) - { - result = 0; - } - else - { - result = DefWindowProc( - hWnd, - uMsg, - wParam, - lParam - ); - } if (uMsg == WM_NCDESTROY) { SetWindowLongPtrW( @@ -421,15 +541,6 @@ LRESULT CALLBACK CLauncherTipContextMenu_WndProc( *((HWND*)((char*)_this + 0x78)) = 0; } } - else - { - result = DefWindowProc( - hWnd, - uMsg, - wParam, - lParam - ); - } } return result; } @@ -902,6 +1013,81 @@ LRESULT CALLBACK OpenStartOnCurentMonitorThreadHook( return CallNextHookEx(NULL, code, wParam, lParam); } +DWORD ArchiveMenuThread(LPVOID unused) +{ + Sleep(1000); + + HRESULT hr = CoInitialize(NULL); + if (FAILED(hr)) + { + return 0; + } + + WNDCLASS wc = { 0 }; + wc.style = CS_DBLCLKS; + wc.lpfnWndProc = CLauncherTipContextMenu_WndProc; + wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + wc.hInstance = GetModuleHandle(NULL); + wc.lpszClassName = L"ArchiveMenuWindowExplorer"; + wc.hCursor = LoadCursorW(NULL, IDC_ARROW); + RegisterClass(&wc); + + archivehWnd = CreateWindowInBand( + 0, + L"ArchiveMenuWindowExplorer", + 0, + WS_POPUP, + 0, + 0, + 0, + 0, + 0, + 0, + GetModuleHandle(NULL), + NULL, + 7 + ); + if (!archivehWnd) + { + return 0; + } + ITaskbarList* pTaskList = NULL; + hr = CoCreateInstance( + &__uuidof_TaskbarList, + NULL, + CLSCTX_ALL, + &__uuidof_ITaskbarList, + (void**)(&pTaskList) + ); + if (FAILED(hr)) + { + return 0; + } + hr = pTaskList->lpVtbl->HrInit(pTaskList); + if (FAILED(hr)) + { + return 0; + } + ShowWindow(archivehWnd, SW_SHOW); + hr = pTaskList->lpVtbl->DeleteTab(pTaskList, archivehWnd); + if (FAILED(hr)) + { + return 0; + } + hr = pTaskList->lpVtbl->Release(pTaskList); + if (FAILED(hr)) + { + return 0; + } + + MSG msg = { 0 }; + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } +} + DWORD OpenStartOnCurentMonitorThread(LPVOID unused) { HWND g_ProgWin = FindWindowEx( @@ -962,16 +1148,6 @@ __declspec(dllexport) DWORD WINAPI main( - CreateThread( - 0, - 0, - OpenStartOnCurentMonitorThread, - 0, - 0, - 0 - ); - - DWORD dwRet = 0; char szSettingsPath[MAX_PATH]; @@ -1003,6 +1179,41 @@ __declspec(dllexport) DWORD WINAPI main( MAX_PATH ); + + + UINT archive_plugin = VnGetUInt( + L"ArchiveMenu", + L"Enabled", + 0, + wszSettingsPath + ); + if (archive_plugin) + { + CreateThread( + 0, + 0, + ArchiveMenuThread, + 0, + 0, + 0 + ); + } + + + + + CreateThread( + 0, + 0, + OpenStartOnCurentMonitorThread, + 0, + 0, + 0 + ); + + + + symbols_addr symbols_PTRS; ZeroMemory( &symbols_PTRS, diff --git a/PostBuildCommand/PostBuildCommand.vcxproj b/PostBuildCommand/PostBuildCommand.vcxproj index 30abf7308..af2b2c4f9 100644 --- a/PostBuildCommand/PostBuildCommand.vcxproj +++ b/PostBuildCommand/PostBuildCommand.vcxproj @@ -63,10 +63,10 @@ - rem taskkill /f /im:sihost.exe 2>nul &set errorlevel=0 + taskkill /f /im:sihost.exe 2>nul &set errorlevel=0 PostBuildCommand.exe NDEBUG;$(NMakePreprocessorDefinitions) - rem taskkill /f /im:sihost.exe 2>nul &set errorlevel=0 + taskkill /f /im:sihost.exe 2>nul &set errorlevel=0 rem taskkill /f /im:sihost.exe 2>nul &set errorlevel=0 diff --git a/PreBuildCommand/PreBuildCommand.vcxproj b/PreBuildCommand/PreBuildCommand.vcxproj index 465143adf..927f43db4 100644 --- a/PreBuildCommand/PreBuildCommand.vcxproj +++ b/PreBuildCommand/PreBuildCommand.vcxproj @@ -63,10 +63,10 @@ - rem taskkill /f /im:explorer.exe 2>nul &set errorlevel=0 + taskkill /f /im:explorer.exe 2>nul &set errorlevel=0 PreBuildCommand.exe NDEBUG;$(NMakePreprocessorDefinitions) - rem taskkill /f /im:explorer.exe 2>nul &set errorlevel=0 + taskkill /f /im:explorer.exe 2>nul &set errorlevel=0 rem taskkill /f /im:explorer.exe 2>nul &set errorlevel=0 diff --git a/README.md b/README.md index 10cb2af6a..e1c087c0b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Explorer Patcher is a patcher that enables various stuff in Explorer. For the mo * enables the power user menu (Win+X) when using the classic taskbar in Windows 11 * shows the Start menu on the monitor containing the cursor when invoked with the Windows key -This heas been tested on the following builds: +This has been tested on the following builds: * 22000.1 - works as advertised, tested with `Start_ShowClassicMode` which shows the Windows 10 Start menu; taskbar works, Win+X works and is skinned, WiFi flyout works, battery flyout works, no delay at logon * 22000.168 - works as advertised, Start button opens Windows 11 Start menu (a half broken Windows 10 menu can be restored by copying `StartMenuExperienceHost.exe` and its DLLs from 22000.1); taskbar works, Win+X works and is skinned, WiFi flyout DOES NOT work (use control center aka gear icon or [enable Windows 8 network flyout](https://winaero.com/change-network-icon-click-action-in-windows-10/?utm_source=software&utm_medium=in-app&utm_campaign=winaerotweaker&utm_content=networkflyout) instead, battery flyout DOES NOT work (use [Battery Mode](https://en.bmode.tarcode.ru/) utility), control center icon works, no delay at logon (!!!)