From 8119c5aa7c7a6427b43d8f464cf590ef6ef5406e Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Fri, 21 Jan 2022 14:50:17 +0200 Subject: [PATCH] Reduced symbol dependency for Win+C hook --- CHANGELOG.md | 1 + ExplorerPatcher/ExplorerPatcher.vcxproj | 2 + ExplorerPatcher/dllmain.c | 100 +++++++++++++++++++++--- ExplorerPatcher/settings.reg | 4 +- ExplorerPatcher/symbols.h | 2 +- version.h | 6 +- 6 files changed, 99 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7c84a..dcb5a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Tested on OS build 22000.434. * Windows 10 (with link to "Language Preferences") * Windows 10 * Simple Window Switcher now highlights windows that require user attention (windows that have their taskbar button flash and colored in orange) (.8) +* Reliability improvements for the option that maps the `Win`+`C` shortcut to open the clock flyout instead of Microsoft Teams (eliminated dependency on symbol data) (.10) #### Fixes diff --git a/ExplorerPatcher/ExplorerPatcher.vcxproj b/ExplorerPatcher/ExplorerPatcher.vcxproj index dc07bf1..558c947 100644 --- a/ExplorerPatcher/ExplorerPatcher.vcxproj +++ b/ExplorerPatcher/ExplorerPatcher.vcxproj @@ -206,6 +206,8 @@ EP_DWM_NO_DLLMAIN;EP_DWM_NO_EXPORTS;%(PreprocessorDefinitions) EP_DWM_NO_DLLMAIN;EP_DWM_NO_EXPORTS;%(PreprocessorDefinitions) EP_DWM_NO_DLLMAIN;EP_DWM_NO_EXPORTS;%(PreprocessorDefinitions) + true + true true diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index d0e0302..e44d372 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -162,11 +162,13 @@ HRESULT WINAPI _DllGetClassObject( REFIID riid, LPVOID* ppv ); +#ifdef _WIN64 BOOL ep_dwm_StartService(LPWSTR wszServiceName, LPWSTR wszEventName); __declspec(dllexport) int ZZDWM(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) { ep_dwm_StartService(L"ep_dwm_Service_" _T(EP_CLSID), L"Global\\ep_dwm_" _T(EP_CLSID)); } +#endif #pragma region "Updates" #ifdef _WIN64 @@ -709,6 +711,77 @@ void LaunchNetworkTargets(DWORD dwTarget) #pragma endregion +#pragma region "Service Window" +#ifdef _WIN64 +#define EP_SERVICE_WINDOW_CLASS_NAME L"EP_Service_Window_" _T(EP_CLSID) +LRESULT CALLBACK EP_Service_Window_WndProc( + HWND hWnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + if (uMsg == WM_HOTKEY && (wParam == 1 || wParam == 2)) + { + InvokeClockFlyout(); + return 0; + } + + return DefWindowProcW(hWnd, uMsg, wParam, lParam); +} +DWORD EP_ServiceWindowThread(DWORD unused) +{ + WNDCLASS wc = { 0 }; + wc.style = CS_DBLCLKS; + wc.lpfnWndProc = EP_Service_Window_WndProc; + wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + wc.hInstance = GetModuleHandle(NULL); + wc.lpszClassName = EP_SERVICE_WINDOW_CLASS_NAME; + wc.hCursor = LoadCursorW(NULL, IDC_ARROW); + RegisterClassW(&wc); + + HWND hWnd = CreateWindowExW( + 0, + EP_SERVICE_WINDOW_CLASS_NAME, + 0, + WS_POPUP, + 0, + 0, + 0, + 0, + 0, + 0, + GetModuleHandle(NULL), + NULL + ); + if (hWnd) + { + if (bClockFlyoutOnWinC) + { + RegisterHotKey(hWnd, 1, MOD_WIN | MOD_NOREPEAT, 'C'); + } + RegisterHotKey(hWnd, 2, MOD_WIN | MOD_ALT, 'D'); + MSG msg; + BOOL bRet; + while ((bRet = GetMessageW(&msg, NULL, 0, 0)) != 0) + { + if (bRet == -1) + { + break; + } + else + { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + } + DestroyWindow(hWnd); + } + SetEvent(hCanStartSws); +} +#endif +#pragma endregion + + #pragma region "Toggle shell features" BOOL CALLBACK ToggleImmersiveCallback(HWND hWnd, LPARAM lParam) { @@ -1655,7 +1728,6 @@ INT64 Shell_TrayWndSubclassProc( if (bIsPrimaryTaskbar) { UnhookWindowsHookEx(Shell_TrayWndMouseHook); - UnregisterHotKey(hWnd, 'VNEP'); } RemoveWindowSubclass(hWnd, Shell_TrayWndSubclassProc, Shell_TrayWndSubclassProc); } @@ -1677,11 +1749,6 @@ INT64 Shell_TrayWndSubclassProc( ToggleTaskbarAutohide(); return 0; } - else if (uMsg == WM_HOTKEY && lParam == MAKELPARAM(MOD_WIN | MOD_ALT, 0x44)) - { - InvokeClockFlyout(); - return 0; - } else if (uMsg == WM_HOTKEY && wParam == 500 && lParam == MAKELPARAM(MOD_WIN, 0x41)) { InvokeActionCenter(); @@ -3105,7 +3172,7 @@ HRESULT pnidui_CoCreateInstanceHook( #pragma endregion -#pragma region "Show Clock flyout on Win+C and Win+Alt+D" +#pragma region "Clock flyout helper" #ifdef _WIN64 typedef struct _ClockButton_ToggleFlyoutCallback_Params { @@ -4914,7 +4981,6 @@ HWND CreateWindowExWHook( else if (bIsExplorerProcess && (*((WORD*)&(lpClassName)+1)) && !wcscmp(lpClassName, L"Shell_TrayWnd")) { SetWindowSubclass(hWnd, Shell_TrayWndSubclassProc, Shell_TrayWndSubclassProc, TRUE); - RegisterHotKey(hWnd, 'VNEP', MOD_WIN | MOD_ALT, 0x44); Shell_TrayWndMouseHook = SetWindowsHookExW(WH_MOUSE, Shell_TrayWndMouseProc, NULL, GetCurrentThreadId()); } else if (bIsExplorerProcess && (*((WORD*)&(lpClassName)+1)) && !wcscmp(lpClassName, L"Shell_SecondaryTrayWnd")) @@ -6885,7 +6951,7 @@ DWORD Inject(BOOL bIsExplorer) } } - if (symbols_PTRS.twinui_pcshell_PTRS[TWINUI_PCSHELL_SB_CNT - 1] && symbols_PTRS.twinui_pcshell_PTRS[TWINUI_PCSHELL_SB_CNT - 1] != 0xFFFFFFFF) + /*if (symbols_PTRS.twinui_pcshell_PTRS[TWINUI_PCSHELL_SB_CNT - 1] && symbols_PTRS.twinui_pcshell_PTRS[TWINUI_PCSHELL_SB_CNT - 1] != 0xFFFFFFFF) { winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageFunc = (INT64(*)(void*, POINT*)) ((uintptr_t)hTwinuiPcshell + symbols_PTRS.twinui_pcshell_PTRS[TWINUI_PCSHELL_SB_CNT - 1]); @@ -6899,7 +6965,7 @@ DWORD Inject(BOOL bIsExplorer) FreeLibraryAndExitThread(hModule, rv); return rv; } - } + }*/ VnPatchIAT(hTwinuiPcshell, "API-MS-WIN-CORE-REGISTRY-L1-1-0.DLL", "RegGetValueW", twinuipcshell_RegGetValueW); //VnPatchIAT(hTwinuiPcshell, "api-ms-win-core-debug-l1-1-0.dll", "IsDebuggerPresent", IsDebuggerPresentHook); printf("Setup twinui.pcshell functions done\n"); @@ -7093,6 +7159,7 @@ DWORD Inject(BOOL bIsExplorer) } + CreateThread( 0, 0, @@ -7104,6 +7171,19 @@ DWORD Inject(BOOL bIsExplorer) printf("Open Start on monitor thread\n"); + + CreateThread( + 0, + 0, + EP_ServiceWindowThread, + 0, + 0, + 0 + ); + printf("EP Service Window thread\n"); + + + if (bDisableOfficeHotkeys) { VnPatchIAT(hExplorer, "user32.dll", "RegisterHotKey", explorer_RegisterHotkeyHook); diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 6d7dd53..fdb0360 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -350,7 +350,7 @@ [HKEY_CURRENT_USER\Software\ExplorerPatcher] ;b Remember last used section in this window "LastSectionInProperties"=dword:00000000 -;b Open clock flyout when pressing Win+C instead of Microsoft Teams +;b Open clock flyout when pressing Win+C instead of Microsoft Teams * "ClockFlyoutOnWinC"=dword:00000000 ;b Show separators between taskbar toolbars * "ToolbarSeparators"=dword:00000000 @@ -433,7 +433,7 @@ ;d Enable SysListView32 for Explorer views * @="" [HKEY_CURRENT_USER\Software\ExplorerPatcher] -;b Do not show the program settings item ("Properties") in the taskbar context menu +;b Hide the program settings item ("Properties") from the taskbar context menu "NoPropertiesInContextMenu"=dword:00000000 ;b Enable symbols download * "EnableSymbolDownload"=dword:00000001 diff --git a/ExplorerPatcher/symbols.h b/ExplorerPatcher/symbols.h index 5f10320..eb6174a 100644 --- a/ExplorerPatcher/symbols.h +++ b/ExplorerPatcher/symbols.h @@ -18,7 +18,7 @@ #define TWINUI_PCSHELL_SB_5 "CLauncherTipContextMenu::_ExecuteCommand" #define TWINUI_PCSHELL_SB_6 "CLauncherTipContextMenu::ShowLauncherTipContextMenu" #define TWINUI_PCSHELL_SB_7 "IsUndockedAssetAvailable" -#define TWINUI_PCSHELL_SB_8 "winrt::Windows::Internal::Shell::implementation::MeetAndChatManager::OnMessage" // should be always last +#define TWINUI_PCSHELL_SB_8 "CLauncherTipContextMenu::ShowLauncherTipContextMenu" //"winrt::Windows::Internal::Shell::implementation::MeetAndChatManager::OnMessage" // should be always last #define TWINUI_PCSHELL_SB_CNT 9 #define STARTDOCKED_SB_NAME "StartDocked" #define STARTDOCKED_SB_0 "StartDocked::LauncherFrame::ShowAllApps" // UNUSED diff --git a/version.h b/version.h index 7b3f325..3529d36 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define VER_MAJOR 22000 #define VER_MINOR 434 #define VER_BUILD_HI 41 -#define VER_BUILD_LO 9 +#define VER_BUILD_LO 10 #define VER_FLAGS VS_FF_PRERELEASE @@ -12,5 +12,5 @@ #define VER_STR(arg) #arg // The String form of the version numbers -#define VER_FILE_STRING VALUE "FileVersion", "22000.434.41.9" -#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.434.41.9" +#define VER_FILE_STRING VALUE "FileVersion", "22000.434.41.10" +#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.434.41.10"