From 7cc02b72d47f324c3718e6c8089ea5d2a3161a8a Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Fri, 21 Jan 2022 13:06:46 +0200 Subject: [PATCH] Option to disable rounded corners for windows --- .gitmodules | 3 + CHANGELOG.md | 1 + ExplorerPatcher/ExplorerPatcher.vcxproj | 7 + .../ExplorerPatcher.vcxproj.filters | 12 ++ ExplorerPatcher/GUI.c | 188 +++++++++++++++++- ExplorerPatcher/dllmain.c | 6 +- ExplorerPatcher/settings.reg | 2 + ExplorerPatcher/utility.h | 1 + ep_dwm | 1 + ep_setup/ep_setup.c | 29 +++ version.h | 6 +- 11 files changed, 248 insertions(+), 8 deletions(-) create mode 160000 ep_dwm diff --git a/.gitmodules b/.gitmodules index 997fac9..09c73f9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "libs/sws"] path = libs/sws url = https://github.com/valinet/sws +[submodule "ep_dwm"] + path = ep_dwm + url = https://github.com/valinet/ep_dwm diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca825e..092df27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Tested on OS build 22000.434. * Support for screen readers in the Properties window (#627) (.1) * Option to disable `Office` hotkeys (`Ctrl`+`Alt`+`Shift`+`Windows` key combinations) (#661) (.4) * Simple Window Switcher can switch applications instead of windows (#665) (.5, .6) +* Option to disable rounded corners for windows (.7) #### Feature enhancements diff --git a/ExplorerPatcher/ExplorerPatcher.vcxproj b/ExplorerPatcher/ExplorerPatcher.vcxproj index c3fd7c8..dc07bf1 100644 --- a/ExplorerPatcher/ExplorerPatcher.vcxproj +++ b/ExplorerPatcher/ExplorerPatcher.vcxproj @@ -201,6 +201,12 @@ + + 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) + EP_DWM_NO_DLLMAIN;EP_DWM_NO_EXPORTS;%(PreprocessorDefinitions) + true true @@ -292,6 +298,7 @@ + diff --git a/ExplorerPatcher/ExplorerPatcher.vcxproj.filters b/ExplorerPatcher/ExplorerPatcher.vcxproj.filters index e13a797..0619f17 100644 --- a/ExplorerPatcher/ExplorerPatcher.vcxproj.filters +++ b/ExplorerPatcher/ExplorerPatcher.vcxproj.filters @@ -28,6 +28,12 @@ {190d08ad-4a1d-4b58-81a1-6403eeb3cd2a} + + {50a6ac61-12c4-460e-a9d1-cdaf9bf7e7b1} + + + {fd25654b-7123-401a-86c7-90413d703f30} + @@ -123,6 +129,9 @@ Header Files\sws + + Header Files\ep_dwm + @@ -202,6 +211,9 @@ Source Files\sws + + Source Files\ep_dwm + diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index 7248f10..de8961e 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -317,6 +317,100 @@ LSTATUS GUI_RegSetValueExW( ); return RegSetValueExW(hKey, L"Start_MaximumFrequentApps", 0, dwType, lpData, cbData); } + else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_DisableRoundedCorners")) + { + WCHAR wszPath[MAX_PATH]; + GetSystemDirectoryW(wszPath, MAX_PATH); + wcscat_s(wszPath, MAX_PATH, L"\\cmd.exe"); + + WCHAR wszSCPath[MAX_PATH]; + GetSystemDirectoryW(wszSCPath, MAX_PATH); + wcscat_s(wszSCPath, MAX_PATH, L"\\sc.exe"); + + WCHAR wszRundll32[MAX_PATH]; + GetSystemDirectoryW(wszRundll32, MAX_PATH); + wcscat_s(wszRundll32, MAX_PATH, L"\\rundll32.exe"); + + WCHAR wszEP[MAX_PATH]; + GetWindowsDirectoryW(wszEP, MAX_PATH); + wcscat_s(wszEP, MAX_PATH, L"\\dxgi.dll"); + + WCHAR wszTaskkill[MAX_PATH]; + GetSystemDirectoryW(wszTaskkill, MAX_PATH); + wcscat_s(wszTaskkill, MAX_PATH, L"\\taskkill.exe"); + + WCHAR wszArgumentsRegister[MAX_PATH * 10]; + swprintf_s( + wszArgumentsRegister, + MAX_PATH * 10, + L"/c \"" + L"\"%s\" create ep_dwm_" _T(EP_CLSID_LITE) L" binPath= \"\\\"%s\\\" \\\"%s\\\",ZZDWM\" DisplayName= \"ExplorerPatcher Desktop Window Manager Service\" start= auto & " + L"\"%s\" description ep_dwm_" _T(EP_CLSID_LITE) L" \"Implements functionality to disable rounded corners for windows\" & " + L"\"%s\" start ep_dwm_" _T(EP_CLSID_LITE) + L"\"", + wszSCPath, + wszRundll32, + wszEP, + wszSCPath, + wszSCPath + ); + WCHAR wszArgumentsUnRegister[MAX_PATH * 10]; + swprintf_s( + wszArgumentsUnRegister, + MAX_PATH * 10, + L"/c \"" + L"\"%s\" stop ep_dwm_" _T(EP_CLSID_LITE) L" & " + L"\"%s\" delete ep_dwm_" _T(EP_CLSID_LITE) L" & " + L"\"", + wszSCPath, + wszSCPath + ); + wprintf(L"%s\n", wszArgumentsRegister); + + BOOL bAreRoundedCornersDisabled = FALSE; + HANDLE h_exists = CreateEventW(NULL, FALSE, FALSE, L"Global\\ep_dwm_" _T(EP_CLSID)); + if (h_exists) + { + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + bAreRoundedCornersDisabled = TRUE; + } + else + { + bAreRoundedCornersDisabled = FALSE; + } + CloseHandle(h_exists); + } + else + { + if (GetLastError() == ERROR_ACCESS_DENIED) + { + bAreRoundedCornersDisabled = TRUE; + } + else + { + bAreRoundedCornersDisabled = FALSE; + } + } + SHELLEXECUTEINFO ShExecInfo = { 0 }; + ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + ShExecInfo.hwnd = NULL; + ShExecInfo.lpVerb = L"runas"; + ShExecInfo.lpFile = wszPath; + ShExecInfo.lpParameters = !bAreRoundedCornersDisabled ? wszArgumentsRegister : wszArgumentsUnRegister; + ShExecInfo.lpDirectory = NULL; + ShExecInfo.nShow = SW_HIDE; + ShExecInfo.hInstApp = NULL; + if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess) + { + WaitForSingleObject(ShExecInfo.hProcess, INFINITE); + DWORD dwExitCode = 0; + GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); + CloseHandle(ShExecInfo.hProcess); + } + return ERROR_SUCCESS; + } } LSTATUS GUI_RegQueryValueExW( @@ -417,6 +511,34 @@ LSTATUS GUI_RegQueryValueExW( { return RegQueryValueExW(hKey, L"Start_MaximumFrequentApps", lpReserved, lpType, lpData, lpcbData); } + else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_DisableRoundedCorners")) + { + HANDLE h_exists = CreateEventW(NULL, FALSE, FALSE, L"Global\\ep_dwm_" _T(EP_CLSID)); + if (h_exists) + { + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + *(DWORD*)lpData = 1; + } + else + { + *(DWORD*)lpData = 0; + } + CloseHandle(h_exists); + } + else + { + if (GetLastError() == ERROR_ACCESS_DENIED) + { + *(DWORD*)lpData = 1; + } + else + { + *(DWORD*)lpData = 0; + } + } + return ERROR_SUCCESS; + } } static HRESULT GUI_AboutProc( @@ -1185,8 +1307,34 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) { CloseHandle(hFile); + BOOL bAreRoundedCornersDisabled = FALSE; + HANDLE h_exists = CreateEventW(NULL, FALSE, FALSE, L"Global\\ep_dwm_" _T(EP_CLSID)); + if (h_exists) + { + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + bAreRoundedCornersDisabled = TRUE; + } + else + { + bAreRoundedCornersDisabled = FALSE; + } + CloseHandle(h_exists); + } + else + { + if (GetLastError() == ERROR_ACCESS_DENIED) + { + bAreRoundedCornersDisabled = TRUE; + } + else + { + bAreRoundedCornersDisabled = FALSE; + } + } + DWORD dwError = 1; - if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + if ((hKey == NULL || hKey == INVALID_HANDLE_VALUE) && !bAreRoundedCornersDisabled) { dwError = 0; // https://stackoverflow.com/questions/50298722/win32-launching-a-highestavailable-child-process-as-a-normal-user-process @@ -1256,13 +1404,45 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) } if (dwError) { + WCHAR wszCMD[MAX_PATH]; + GetSystemDirectoryW(wszCMD, MAX_PATH); + wcscat_s(wszCMD, MAX_PATH, L"\\cmd.exe"); + + WCHAR wszRegedit[MAX_PATH]; + GetWindowsDirectoryW(wszRegedit, MAX_PATH); + wcscat_s(wszRegedit, MAX_PATH, L"\\regedit.exe"); + + WCHAR wszSCPath[MAX_PATH]; + GetSystemDirectoryW(wszSCPath, MAX_PATH); + wcscat_s(wszSCPath, MAX_PATH, L"\\sc.exe"); + + WCHAR wszTaskkill[MAX_PATH]; + GetSystemDirectoryW(wszTaskkill, MAX_PATH); + wcscat_s(wszTaskkill, MAX_PATH, L"\\taskkill.exe"); + + WCHAR wszArguments[MAX_PATH * 10]; + swprintf_s( + wszArguments, + MAX_PATH * 10, + L"/c \"" + L"\"%s\" \"%s\" & " + L"\"%s\" stop ep_dwm_" _T(EP_CLSID_LITE) L" & " + L"\"%s\" delete ep_dwm_" _T(EP_CLSID_LITE) + L"\"", + wszRegedit, + wszPath, + wszSCPath, + wszSCPath + ); + wprintf(L"%s\n", wszArguments); + SHELLEXECUTEINFO ShExecInfo = { 0 }; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; - ShExecInfo.lpVerb = NULL; - ShExecInfo.lpFile = wszPath; - ShExecInfo.lpParameters = L""; + ShExecInfo.lpVerb = L"runas"; + ShExecInfo.lpFile = wszCMD; + ShExecInfo.lpParameters = wszArguments; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 72c7b78..bc30667 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -161,7 +161,11 @@ HRESULT WINAPI _DllGetClassObject( REFIID riid, LPVOID* ppv ); - +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)); +} #pragma region "Updates" #ifdef _WIN64 diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 63c5218..790991f 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -364,6 +364,8 @@ "NoMenuAccelerator"=dword:00000000 ;b Disable Office hotkeys (Ctrl+Alt+Shift+Windows key combinations) * "DisableOfficeHotkeys"=dword:00000000 +;b Disable rounded corners for application windows +"Virtualized_{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}_DisableRoundedCorners"=dword:00000000 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] ;c 6 Default action in the Alt+F4 dialog on the desktop ;x 256 Switch user diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index 5fbd3b5..f7e1064 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -28,6 +28,7 @@ #define PRODUCT_NAME "ExplorerPatcher" #define PRODUCT_PUBLISHER "VALINET Solutions SRL" #define APP_RELATIVE_PATH "\\" PRODUCT_NAME +#define EP_CLSID_LITE "D17F1E1A-5919-4427-8F89-A1A8503CA3EB" #define EP_CLSID "{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}" #define DOSMODE_OFFSET 78 #define SETUP_UTILITY_NAME "ep_setup.exe" diff --git a/ep_dwm b/ep_dwm new file mode 160000 index 0000000..e058f2e --- /dev/null +++ b/ep_dwm @@ -0,0 +1 @@ +Subproject commit e058f2e8cc13dc094ba55f472a1ade969d260526 diff --git a/ep_setup/ep_setup.c b/ep_setup/ep_setup.c index a94000e..cfad35a 100644 --- a/ep_setup/ep_setup.c +++ b/ep_setup/ep_setup.c @@ -434,6 +434,27 @@ int WINAPI wWinMain( CloseHandle(sei.hProcess); } + WCHAR wszSCPath[MAX_PATH]; + GetSystemDirectoryW(wszSCPath, MAX_PATH); + wcscat_s(wszSCPath, MAX_PATH, L"\\sc.exe"); + SHELLEXECUTEINFO ShExecInfo = { 0 }; + ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + ShExecInfo.hwnd = NULL; + ShExecInfo.lpVerb = L"runas"; + ShExecInfo.lpFile = wszSCPath; + ShExecInfo.lpParameters = L"stop ep_dwm_" _T(EP_CLSID_LITE); + ShExecInfo.lpDirectory = NULL; + ShExecInfo.nShow = SW_HIDE; + ShExecInfo.hInstApp = NULL; + if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess) + { + WaitForSingleObject(ShExecInfo.hProcess, INFINITE); + DWORD dwExitCode = 0; + GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); + CloseHandle(ShExecInfo.hProcess); + } + HWND hWnd = FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL); if (hWnd) { @@ -591,6 +612,14 @@ int WINAPI wWinMain( wcscat_s(wszPath, MAX_PATH, _T(APP_RELATIVE_PATH) L"\\" _T(SETUP_UTILITY_NAME) L"\" /uninstall"); bOk = SetupUninstallEntry(bInstall, wszPath); } + ShExecInfo.lpParameters = bInstall ? L"start ep_dwm_" _T(EP_CLSID_LITE) : L"delete ep_dwm_" _T(EP_CLSID_LITE); + if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess) + { + WaitForSingleObject(ShExecInfo.hProcess, INFINITE); + DWORD dwExitCode = 0; + GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); + CloseHandle(ShExecInfo.hProcess); + } if (bOk) { diff --git a/version.h b/version.h index f3d645c..4d575cf 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 6 +#define VER_BUILD_LO 7 #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.6" -#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.434.41.6" +#define VER_FILE_STRING VALUE "FileVersion", "22000.434.41.7" +#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.434.41.7"