From 25d21d8ed004dcc3ad61015ec47e223116c4022a Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Wed, 13 Oct 2021 06:36:30 +0300 Subject: [PATCH] System tray icon improvements --- CHANGELOG.md | 7 +++ ExplorerPatcher/ExplorerPatcher.rc | 8 +-- ExplorerPatcher/dllmain.c | 96 ++++++++++++++++++++++++++++++ ExplorerPatcher/settings.reg | 4 +- 4 files changed, 110 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4427288..a22a124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ This document includes the same release notes as in the [Releases](https://github.com/valinet/ExplorerPatcher/releases) section on GitHub. +## 22000.194.0.26 + +Tested on build: 22000.194. + +* Option to open Network and Sharing Center instead if Network settings when right clicking the network icon in the system tray +* Centered network and sound right click menus and made them toggle on right click + ## 22000.194.0.25 Tested on build: 22000.194. diff --git a/ExplorerPatcher/ExplorerPatcher.rc b/ExplorerPatcher/ExplorerPatcher.rc index 2c58a18..29af358 100644 --- a/ExplorerPatcher/ExplorerPatcher.rc +++ b/ExplorerPatcher/ExplorerPatcher.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 22000,194,0,25 - PRODUCTVERSION 22000,194,0,25 + FILEVERSION 22000,194,0,26 + PRODUCTVERSION 22000,194,0,26 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "VALINET Solutions SRL" VALUE "FileDescription", "ExplorerPatcher" - VALUE "FileVersion", "22000.194.0.25" + VALUE "FileVersion", "22000.194.0.26" 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.194.0.25" + VALUE "ProductVersion", "22000.194.0.26" END END BLOCK "VarFileInfo" diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 55983de..a134738 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -26,6 +26,8 @@ #define CHECKFOREGROUNDELAPSED_TIMEOUT 100 #define POPUPMENU_SAFETOREMOVE_TIMEOUT 300 #define POPUPMENU_BLUETOOTH_TIMEOUT 700 +#define POPUPMENU_PNIDUI_TIMEOUT 300 +#define POPUPMENU_SNDVOLSSO_TIMEOUT 300 HWND archivehWnd; HMODULE hStartIsBack64 = 0; @@ -34,6 +36,7 @@ BOOL bMicaEffectOnTitlebar = FALSE; BOOL bHideControlCenterButton = FALSE; BOOL bSkinMenus = TRUE; BOOL bSkinIcons = TRUE; +BOOL bReplaceNetwork = FALSE; HMODULE hModule = NULL; HANDLE hIsWinXShown = NULL; HANDLE hWinXThread = NULL; @@ -696,6 +699,77 @@ void PopupMenuAdjustCoordinatesAndFlags(int* x, int* y, UINT* uFlags) *uFlags |= TPM_VCENTERALIGN | TPM_RIGHTALIGN; } } +long long pnidui_TrackPopupMenuElapsed = 0; +BOOL pnidui_TrackPopupMenuHook( + HMENU hMenu, + UINT uFlags, + int x, + int y, + int nReserved, + HWND hWnd, + const RECT* prcRect +) +{ + long long elapsed = milliseconds_now() - pnidui_TrackPopupMenuElapsed; + BOOL b = FALSE; + if (elapsed > POPUPMENU_PNIDUI_TIMEOUT || !bSkinMenus) + { + if (bSkinMenus) + { + PopupMenuAdjustCoordinatesAndFlags(&x, &y, &uFlags); + } + b = TrackPopupMenu( + hMenu, + uFlags | TPM_RIGHTBUTTON, + x, + y, + 0, + hWnd, + prcRect + ); + if (bReplaceNetwork && b == 3109) + { + ShellExecuteW( + NULL, + L"open", + L"shell:::{8E908FC9-BECC-40f6-915B-F4CA0E70D03D}", + NULL, + NULL, + SW_SHOWNORMAL + ); + b = 0; + } + pnidui_TrackPopupMenuElapsed = milliseconds_now(); + } + return b; +} +long long sndvolsso_TrackPopupMenuExElapsed = 0; +BOOL sndvolsso_TrackPopupMenuExHook( + HMENU hMenu, + UINT uFlags, + int x, + int y, + HWND hWnd, + LPTPMPARAMS lptpm +) +{ + long long elapsed = milliseconds_now() - sndvolsso_TrackPopupMenuExElapsed; + BOOL b = FALSE; + if (elapsed > POPUPMENU_SNDVOLSSO_TIMEOUT) + { + PopupMenuAdjustCoordinatesAndFlags(&x, &y, &uFlags); + b = TrackPopupMenuEx( + hMenu, + uFlags | TPM_RIGHTBUTTON, + x, + y, + hWnd, + lptpm + ); + sndvolsso_TrackPopupMenuExElapsed = milliseconds_now(); + } + return b; +} long long TrackPopupMenuElapsed = 0; BOOL TrackPopupMenuHook( HMENU hMenu, @@ -1540,6 +1614,7 @@ __declspec(dllexport) DWORD WINAPI main( } + dwSize = sizeof(DWORD); RegQueryValueExW( hKey, TEXT("HideExplorerSearchBar"), @@ -1548,6 +1623,7 @@ __declspec(dllexport) DWORD WINAPI main( &bHideExplorerSearchBar, &dwSize ); + dwSize = sizeof(DWORD); RegQueryValueExW( hKey, TEXT("MicaEffectOnTitlebar"), @@ -1556,6 +1632,7 @@ __declspec(dllexport) DWORD WINAPI main( &bMicaEffectOnTitlebar, &dwSize ); + dwSize = sizeof(DWORD); RegQueryValueExW( hKey, TEXT("HideControlCenterButton"), @@ -1564,6 +1641,7 @@ __declspec(dllexport) DWORD WINAPI main( &bHideControlCenterButton, &dwSize ); + dwSize = sizeof(DWORD); RegQueryValueExW( hKey, TEXT("SkinMenus"), @@ -1572,6 +1650,7 @@ __declspec(dllexport) DWORD WINAPI main( &bSkinMenus, &dwSize ); + dwSize = sizeof(DWORD); RegQueryValueExW( hKey, TEXT("SkinIcons"), @@ -1580,6 +1659,15 @@ __declspec(dllexport) DWORD WINAPI main( &bSkinIcons, &dwSize ); + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("ReplaceNetwork"), + 0, + NULL, + &bReplaceNetwork, + &dwSize + ); @@ -1720,6 +1808,10 @@ __declspec(dllexport) DWORD WINAPI main( HANDLE hPnidui = LoadLibraryW(L"pnidui.dll"); VnPatchIAT(hPnidui, "api-ms-win-core-com-l1-1-0.dll", "CoCreateInstance", pnidui_CoCreateInstanceHook); + if (bSkinMenus || bReplaceNetwork) + { + VnPatchIAT(hPnidui, "user32.dll", "TrackPopupMenu", pnidui_TrackPopupMenuHook); + } #ifdef USE_PRIVATE_INTERFACES if (bSkinIcons) { @@ -1732,6 +1824,10 @@ __declspec(dllexport) DWORD WINAPI main( HANDLE hSndvolsso = LoadLibraryW(L"sndvolsso.dll"); + if (bSkinMenus) + { + VnPatchIAT(hSndvolsso, "user32.dll", "TrackPopupMenuEx", sndvolsso_TrackPopupMenuExHook); + } #ifdef USE_PRIVATE_INTERFACES if (bSkinIcons) { diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 3f44f0f..ed55bd9 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -19,11 +19,13 @@ [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher] ;b Disable Control Center button * "HideControlCenterButton"=dword:00000000 -;b Apply immersive style to system tray icon menus * +;b Center and skin system tray icon menus * "SkinMenus"=dword:00000001 ;p 2 ;b Apply Windows 11 style to system tray icons * "SkinIcons"=dword:00000001 +;b Open network settings in Control Panel for system tray icon * +"ReplaceNetwork"=dword:00000000 ;T File Explorer [-HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32]