From d79dfcd8b956acdf4e79c67b06fe193d60542d52 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Thu, 2 Sep 2021 16:14:29 +0300 Subject: [PATCH] Win+C now opens the calendar flyout (previously it opened Cortana but since that is gone, it just crashes Explorer, so better we map it to something useful) --- ExplorerPatcher/ExplorerPatcher.rc | 8 +- ExplorerPatcher/dllmain.c | 171 +++++++++++++++++++++++------ configs/22000.168/settings.ini | 36 ------ 3 files changed, 144 insertions(+), 71 deletions(-) delete mode 100644 configs/22000.168/settings.ini diff --git a/ExplorerPatcher/ExplorerPatcher.rc b/ExplorerPatcher/ExplorerPatcher.rc index 271962b..1af2499 100644 --- a/ExplorerPatcher/ExplorerPatcher.rc +++ b/ExplorerPatcher/ExplorerPatcher.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 22000,168,0,14 - PRODUCTVERSION 22000,168,0,14 + FILEVERSION 22000,168,0,15 + PRODUCTVERSION 22000,168,0,15 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "VALINET Solutions SRL" VALUE "FileDescription", "ExplorerPatcher" - VALUE "FileVersion", "22000.168.0.14" + VALUE "FileVersion", "22000.168.0.15" VALUE "InternalName", "ExplorerPatcher.dll" VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved." VALUE "OriginalFilename", "ExplorerPatcher.dll" VALUE "ProductName", "ExplorerPatcher" - VALUE "ProductVersion", "22000.168.0.14" + VALUE "ProductVersion", "22000.168.0.15" END END BLOCK "VarFileInfo" diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 42e3e29..fb051d8 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -70,7 +70,8 @@ DEFINE_GUID(__uuidof_IAuthUILogonSound, #define TWINUI_PCSHELL_SB_4 "CLauncherTipContextMenu::_ExecuteShutdownCommand" #define TWINUI_PCSHELL_SB_5 "CLauncherTipContextMenu::_ExecuteCommand" #define TWINUI_PCSHELL_SB_6 "CLauncherTipContextMenu::ShowLauncherTipContextMenu" -#define TWINUI_PCSHELL_SB_CNT 7 +#define TWINUI_PCSHELL_SB_7 "winrt::Windows::Internal::Shell::implementation::MeetAndChatManager::OnMessage" +#define TWINUI_PCSHELL_SB_CNT 8 #define TWINUI_SB_NAME "twinui" #define TWINUI_SB_0 "CImmersiveHotkeyNotification::_GetMonitorForHotkeyNotification" #define TWINUI_SB_1 "IsDesktopInputContext" @@ -106,7 +107,8 @@ const char* twinui_pcshell_SN[TWINUI_PCSHELL_SB_CNT] = { TWINUI_PCSHELL_SB_3, TWINUI_PCSHELL_SB_4, TWINUI_PCSHELL_SB_5, - TWINUI_PCSHELL_SB_6 + TWINUI_PCSHELL_SB_6, + TWINUI_PCSHELL_SB_7 }; const char* twinui_SN[TWINUI_SB_CNT] = { TWINUI_SB_0, @@ -393,6 +395,11 @@ static HWND(WINAPI* CreateWindowInBand)( ); +static INT64(*winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageFunc)( + void* _this, + INT64 a2, + INT a3 + ); static INT64(*CLauncherTipContextMenu_ShowLauncherTipContextMenuFunc)( void* _this, @@ -1090,24 +1097,9 @@ DWORD ShowLauncherTipContextMenu( return 0; } -POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) +HWND GetMonitorInfoFromPointForTaskbarFlyoutActivation(POINT ptCursor, DWORD dwFlags, LPMONITORINFO lpMi) { - if (lpBottom) *lpBottom = FALSE; - if (lpRight) *lpRight = FALSE; - POINT point, ptCursor; - point.x = 0; - point.y = 0; - GetCursorPos(&ptCursor); - HMONITOR hMonitor = MonitorFromPoint(ptCursor, MONITOR_DEFAULTTOPRIMARY); - MONITORINFO mi; - mi.cbSize = sizeof(MONITORINFO); - GetMonitorInfo( - MonitorFromPoint( - ptCursor, - MONITOR_DEFAULTTOPRIMARY - ), - &mi - ); + HMONITOR hMonitor = MonitorFromPoint(ptCursor, dwFlags); HWND hWnd = NULL; do { @@ -1117,8 +1109,18 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) L"Shell_SecondaryTrayWnd", NULL ); - if (MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == hMonitor) + if (MonitorFromWindow(hWnd, dwFlags) == hMonitor) { + if (lpMi) + { + GetMonitorInfo( + MonitorFromPoint( + ptCursor, + dwFlags + ), + lpMi + ); + } break; } } while (hWnd); @@ -1132,14 +1134,36 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) ); ptCursor.x = 0; ptCursor.y = 0; - GetMonitorInfo( - MonitorFromPoint( - ptCursor, - MONITOR_DEFAULTTOPRIMARY - ), - &mi - ); + if (lpMi) + { + GetMonitorInfo( + MonitorFromPoint( + ptCursor, + dwFlags + ), + lpMi + ); + } } + return hWnd; +} + +POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) +{ + if (lpBottom) *lpBottom = FALSE; + if (lpRight) *lpRight = FALSE; + POINT point; + point.x = 0; + point.y = 0; + POINT ptCursor; + GetCursorPos(&ptCursor); + MONITORINFO mi; + mi.cbSize = sizeof(MONITORINFO); + HWND hWnd = GetMonitorInfoFromPointForTaskbarFlyoutActivation( + ptCursor, + MONITOR_DEFAULTTOPRIMARY, + &mi + ); if (hWnd) { RECT rc; @@ -1217,6 +1241,52 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) return point; } +INT64 winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageHook( + void* _this, + INT64 a2, + INT a3 +) +{ + if (a2 == 786 && a3 == 107) + { + POINT ptCursor; + GetCursorPos(&ptCursor); + HWND hWnd = GetMonitorInfoFromPointForTaskbarFlyoutActivation( + ptCursor, + MONITOR_DEFAULTTOPRIMARY, + NULL + ); + HWND prev_hWnd = hWnd; + if (hWnd) + { + hWnd = FindWindowEx(hWnd, NULL, TEXT("TrayNotifyWnd"), NULL); + if (hWnd) + { + hWnd = FindWindowEx(hWnd, NULL, TEXT("TrayClockWClass"), NULL); + } + if (!hWnd) + { + hWnd = FindWindowEx(prev_hWnd, NULL, TEXT("ClockButton"), NULL); + } + if (hWnd) + { + RECT rc; + GetWindowRect(hWnd, &rc); + HWND g_ProgWin = FindWindowEx( + NULL, + NULL, + L"Progman", + NULL + ); + SetForegroundWindow(g_ProgWin); + PostMessage(hWnd, WM_LBUTTONDOWN, 0, 0); + PostMessage(hWnd, WM_LBUTTONUP, 0, 0); + } + } + } + return 0; +} + INT64 CLauncherTipContextMenu_ShowLauncherTipContextMenuHook( void* _this, POINT* pt @@ -1653,11 +1723,16 @@ DWORD PlayStartupSound(DWORD unused) return 0; } -DWORD SignalShellReady(DWORD unused) +DWORD SignalShellReady(DWORD wait) { + if (wait) + { + Sleep(wait); + } + printf("Started \"Signal shell ready\" thread.\n"); - while (TRUE) + while (!wait && TRUE) { HWND hWnd = FindWindowEx( NULL, @@ -1684,7 +1759,10 @@ DWORD SignalShellReady(DWORD unused) Sleep(100); } - Sleep(300); + if (!wait) + { + Sleep(600); + } HANDLE hEvent = CreateEvent(0, 0, 0, L"ShellDesktopSwitchEvent"); if (hEvent) @@ -1993,6 +2071,12 @@ DWORD DownloadSymbols(TCHAR* wszSettingsPath) symbols_PTRS.twinui_pcshell_PTRS[6], wszSettingsPath ); + VnWriteUInt( + TEXT(TWINUI_PCSHELL_SB_NAME), + TEXT(TWINUI_PCSHELL_SB_7), + symbols_PTRS.twinui_pcshell_PTRS[7], + wszSettingsPath + ); @@ -2630,6 +2714,12 @@ __declspec(dllexport) DWORD WINAPI main( 0, wszSettingsPath ); + symbols_PTRS.twinui_pcshell_PTRS[7] = VnGetUInt( + TEXT(TWINUI_PCSHELL_SB_NAME), + TEXT(TWINUI_PCSHELL_SB_7), + 0, + wszSettingsPath + ); symbols_PTRS.twinui_PTRS[0] = VnGetUInt( TEXT(TWINUI_SB_NAME), @@ -3212,6 +3302,19 @@ __declspec(dllexport) DWORD WINAPI main( FreeLibraryAndExitThread(hModule, rv); return rv; } + + winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageFunc = (INT64(*)(void*, POINT*)) + ((uintptr_t)hTwinuiPcshell + symbols_PTRS.twinui_pcshell_PTRS[7]); + rv = funchook_prepare( + funchook, + (void**)&winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageFunc, + winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageHook + ); + if (rv != 0) + { + FreeLibraryAndExitThread(hModule, rv); + return rv; + } printf("Setup twinui.pcshell functions done\n"); @@ -3335,11 +3438,17 @@ __declspec(dllexport) DWORD WINAPI main( + UINT delay = VnGetUInt( + TEXT("General"), + TEXT("ExplorerReadyDelay"), + 0, + wszSettingsPath + ); CreateThread( 0, 0, SignalShellReady, - 0, + delay, 0, 0 ); diff --git a/configs/22000.168/settings.ini b/configs/22000.168/settings.ini deleted file mode 100644 index 2f318de..0000000 --- a/configs/22000.168/settings.ini +++ /dev/null @@ -1,36 +0,0 @@ -[explorer] -CTray::_HandleGlobalHotkey=6992 -CTray::v_WndProc=62144 -CTray::_FireDesktopSwitchIfReady=160304 -CTray::Init=186208 -Dirty=0 -Offset=472 -OffsetStrat=1 -OffsetOK=1 -[twinui.pcshell] -CImmersiveContextMenuOwnerDrawHelper::s_ContextMenuWndProc=2183030 -CLauncherTipContextMenu::GetMenuItemsAsync=6072240 -ImmersiveContextMenuHelper::ApplyOwnerDrawToMenu=6242504 -ImmersiveContextMenuHelper::RemoveOwnerDrawFromMenu=6244560 -CLauncherTipContextMenu::_ExecuteShutdownCommand=6131272 -CLauncherTipContextMenu::_ExecuteCommand=6130436 -CLauncherTipContextMenu::ShowLauncherTipContextMenu=6077440 -[twinui] -CImmersiveHotkeyNotification::_GetMonitorForHotkeyNotification=2411916 -IsDesktopInputContext=43992 -CImmersiveHotkeyNotification::OnMessage=410208 -[stobject] -SysTrayWndProc=19808 -HotPlugButtonClick=96336 -[Windows.UI.FileExplorer] -ContextMenuPresenter::DoContextMenu=265520 -[StartDocked] -Windows::UI::Core::IVisibilityChangedEventArgs::Visible::get=402004 -StartDocked::LauncherFrame::ShowAllApps=1609404 -StartDocked::LauncherFrame::OnVisibilityChanged=1601824 -StartDocked::SystemListPolicyProvider::GetMaximumFrequentApps=15376 -StartDocked::StartSizingFrame::StartSizingFrame=1444588 -[Windows.UI.Xaml] -CJupiterWindow::StaticCoreWindowSubclassProc=2038048 -[OS] -Build=10.0.22000.168