diff --git a/CHANGELOG.md b/CHANGELOG.md index 9590adb..b35b45f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,8 @@ Tested on build 22000.318 and 22000.346 (currently in Windows Insider beta and r * Fixed an issue that prevented "Restore default settings" in the "Properties" UI from working (#374) (.3) * Improved some wording in the Properties UI (#377) (.4) * Added option to show separators between toolbars in the taskbar (#379) (.4) +* "Properties" is restarted when doing an install/update and closed when uninstalling the application (.5) +* "Properties" can open the last used section when starting (.5) ## 22000.318.36 diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index d13ed2c..f318312 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -79,6 +79,62 @@ static HRESULT GUI_AboutProc( return S_OK; } +static void GUI_SetSection(GUI* _this, BOOL bCheckEnablement, int dwSection) +{ + _this->section = dwSection; + + HKEY hKey = NULL; + DWORD dwSize = sizeof(DWORD); + RegCreateKeyExW( + HKEY_CURRENT_USER, + TEXT(REGPATH), + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ | KEY_WOW64_64KEY | KEY_WRITE, + NULL, + &hKey, + NULL + ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + return; + } + + BOOL bEnabled = FALSE; + if (bCheckEnablement) + { + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("LastSectionInProperties"), + 0, + NULL, + &bEnabled, + &dwSize + ); + dwSection++; + } + else + { + bEnabled = TRUE; + } + + if (bEnabled) + { + RegSetValueExW( + hKey, + TEXT("LastSectionInProperties"), + 0, + REG_DWORD, + &dwSection, + sizeof(DWORD) + ); + } + + RegCloseKey(hKey); +} + static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) { GUI* _this; @@ -190,6 +246,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) SetBkMode(hdcPaint, TRANSPARENT); } + BOOL bWasSpecifiedSectionValid = FALSE; FILE* f = fmemopen(pRscr, cbRscr, "r"); char* line = malloc(MAX_LINE_LENGTH * sizeof(char)); wchar_t* text = malloc((MAX_LINE_LENGTH + 3) * sizeof(wchar_t)); @@ -198,6 +255,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) size_t bufsiz = MAX_LINE_LENGTH, numChRd = 0, tabOrder = 1, currentSection = -1, topAdj = 0; while ((numChRd = getline(&line, &bufsiz, f)) != -1) { + if (currentSection == _this->section) + { + bWasSpecifiedSectionValid = TRUE; + } if (strcmp(line, "Windows Registry Editor Version 5.00\r\n") && strcmp(line, "\r\n") && (currentSection == -1 || currentSection == _this->section || !strncmp(line, ";T ", 3) || !strncmp(line, ";f", 2))) { #ifndef USE_PRIVATE_INTERFACES @@ -322,7 +383,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) rcTemp.bottom = rcText.bottom; if (PtInRect(&rcTemp, pt)) { - _this->section = currentSection + 1; + GUI_SetSection(_this, TRUE, currentSection + 1); InvalidateRect(hwnd, NULL, FALSE); } } @@ -790,7 +851,8 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) wchar_t* p = wcschr(name, L'"'); if (p) *p = 0; HKEY hKey = NULL; - BOOL bIsHKLM = wcsstr(section, L"HKEY_LOCAL_MACHINE"); + wchar_t* bIsHKLM = wcsstr(section, L"HKEY_LOCAL_MACHINE"); + bIsHKLM = !bIsHKLM ? NULL : ((bIsHKLM - section) < 3); DWORD dwDisposition; DWORD dwSize = sizeof(DWORD); DWORD value = FALSE; @@ -1069,6 +1131,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) { value = !value; } + if (!wcscmp(name, L"LastSectionInProperties") && wcsstr(section, _T(REGPATH)) && value) + { + value = _this->section + 1; + } RegSetValueExW( hKey, name, @@ -1264,6 +1330,11 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) free(name); free(text); free(line); + if (!bWasSpecifiedSectionValid) + { + GUI_SetSection(_this, FALSE, 0); + InvalidateRect(hwnd, NULL, FALSE); + } SelectObject(hdcPaint, hOldFont); if (!hDC) @@ -1310,9 +1381,70 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) dwMaxHeight, SWP_NOZORDER | SWP_NOACTIVATE ); + + DWORD dwReadSection = 0; + + HKEY hKey = NULL; + DWORD dwSize = sizeof(DWORD); + RegCreateKeyExW( + HKEY_CURRENT_USER, + TEXT(REGPATH), + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ | KEY_WOW64_64KEY | KEY_WRITE, + NULL, + &hKey, + NULL + ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } + if (hKey) + { + dwReadSection = 0; + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("LastSectionInProperties"), + 0, + NULL, + &dwReadSection, + &dwSize + ); + if (dwReadSection) + { + _this->section = dwReadSection - 1; + } + dwReadSection = 0; + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("OpenPropertiesAtNextStart"), + 0, + NULL, + &dwReadSection, + &dwSize + ); + if (dwReadSection) + { + _this->section = dwReadSection - 1; + dwReadSection = 0; + RegSetValueExW( + hKey, + TEXT("OpenPropertiesAtNextStart"), + 0, + REG_DWORD, + &dwReadSection, + sizeof(DWORD) + ); + } + RegCloseKey(hKey); + } + _this->bCalcExtent = FALSE; InvalidateRect(hwnd, NULL, FALSE); - } EndBufferedPaint(hBufferedPaint, TRUE); @@ -1444,10 +1576,10 @@ static LRESULT CALLBACK GUI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR return 0; } // this should be determined from the file, but for now it works - else if (wParam >= 0x30 + 1 && wParam <= 0x30 + 9) + else if (wParam >= '1' && wParam <= '9') { _this->tabOrder = 0; - _this->section = wParam - 0x30 - 1; + GUI_SetSection(_this, TRUE, wParam - '1'); InvalidateRect(hWnd, NULL, FALSE); return 0; } @@ -1515,6 +1647,10 @@ static LRESULT CALLBACK GUI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR EndPaint(hWnd, &ps); return 0; } + else if (uMsg == WM_MSG_GUI_SECTION && wParam == WM_MSG_GUI_SECTION_GET) + { + return _this->section + 1; + } return DefWindowProc(hWnd, uMsg, wParam, lParam); } @@ -1528,7 +1664,6 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin } HKEY hKey = NULL; - DWORD dwDisposition; DWORD dwSize = sizeof(DWORD); RegCreateKeyExW( HKEY_CURRENT_USER, @@ -1536,48 +1671,51 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin 0, NULL, REG_OPTION_NON_VOLATILE, - KEY_READ, + KEY_READ | KEY_WOW64_64KEY, NULL, &hKey, - &dwDisposition + NULL ); if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) { hKey = NULL; } DWORD bAllocConsole = FALSE; - RegQueryValueExW( - hKey, - TEXT("AllocConsole"), - 0, - NULL, - &bAllocConsole, - &dwSize - ); - if (bAllocConsole) - { - FILE* conout; - AllocConsole(); - freopen_s( - &conout, - "CONOUT$", - "w", - stdout - ); - } - dwSize = LOCALE_NAME_MAX_LENGTH; - locale = GetUserDefaultUILanguage(); - RegQueryValueExW( - hKey, - TEXT("Language"), - 0, - NULL, - &locale, - &dwSize - ); if (hKey) { - RegCloseKey(hKey); + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("AllocConsole"), + 0, + NULL, + &bAllocConsole, + &dwSize + ); + if (bAllocConsole) + { + FILE* conout; + AllocConsole(); + freopen_s( + &conout, + "CONOUT$", + "w", + stdout + ); + } + } + locale = GetUserDefaultUILanguage(); + dwSize = LOCALE_NAME_MAX_LENGTH; + if (hKey) + { + RegQueryValueExW( + hKey, + TEXT("Language"), + 0, + NULL, + &locale, + &dwSize + ); } wchar_t wszPath[MAX_PATH]; @@ -1620,6 +1758,7 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); GUI _this; + ZeroMemory(&_this, sizeof(GUI)); _this.hBackgroundBrush = (HBRUSH)(CreateSolidBrush(RGB(255, 255, 255)));// (HBRUSH)GetStockObject(BLACK_BRUSH); _this.location.x = GUI_POSITION_X; _this.location.y = GUI_POSITION_Y; @@ -1749,6 +1888,10 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin } } ShowWindow(hwnd, SW_SHOW); + if (hKey) + { + RegCloseKey(hKey); + } MSG msg = { 0 }; while (GetMessage(&msg, NULL, 0, 0)) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index b655fd5..fd47f7b 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -3430,16 +3430,9 @@ void WINAPI LoadSettings(BOOL bIsExplorer) ); if (dwTemp) { +#ifdef _WIN64 LaunchPropertiesGUI(hModule); - dwTemp = 0; - RegSetValueExW( - hKey, - TEXT("OpenPropertiesAtNextStart"), - 0, - REG_DWORD, - &dwTemp, - sizeof(DWORD) - ); +#endif } RegCloseKey(hKey); } diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 6c940ac..9dbd9e8 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -10,7 +10,7 @@ "OldTaskbar"=dword:00000001 ;y More taskbar options in the Settings app 🡕 ;ms-settings:taskbar -;t The following additional settings only apply to the Windows 10 taskbar: +;t The following settings only apply to the Windows 10 taskbar: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] ;c 3 Combine taskbar icons on main taskbar ;x 0 Always combine @@ -46,11 +46,13 @@ [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher] ;b Show separators between toolbars * "ToolbarSeparators"=dword:00000000 -;b Add shortcut to program settings in Win+X menu -"PropertiesInWinX"=dword:00000000 +;t +;t ;T System tray -;y Enable missing system tray icons 🡕 +;y Customize notification area icons 🡕 +;shell:::{05d7b0f4-2121-4eff-bf6b-ed3f69b894d9} +;y Customize system icons in the notification area 🡕 ;shell:::{05d7b0f4-2121-4eff-bf6b-ed3f69b894d9}\SystemIcons [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] ;b Show seconds in the clock @@ -131,8 +133,8 @@ @="{64bc32b5-4eec-4de7-972d-bd8bd0324537}" ;t ________________________ -;e For the settings marked with (**) to work in Open/Save file dialogs as well, register this -;e utility as shell extension using the option above. +;e For the settings marked with (**) to work in Open/Save file dialogs as well, register +;e this utility as shell extension using the option above. ;y Learn more 🡕 ;https://github.com/valinet/ExplorerPatcher/wiki/Using-ExplorerPatcher-as-shell-extension @@ -286,11 +288,21 @@ ;T Other -[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher] +[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher] +;b Remember last used section in this window +"LastSectionInProperties"=dword:00000000 ;b Open clock flyout when pressing Win+C instead of Microsoft Teams "ClockFlyoutOnWinC"=dword:00000000 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] -;c 6 Default action in shutdown dialog (Alt+F4 on desktop) +;b Show Command Prompt instead of PowerShell in Win+X menu * +"DontUsePowerShellOnWinX"=dword:00000000 +[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher] +;b Add shortcut to program settings in Win+X menu +"PropertiesInWinX"=dword:00000000 +;b Remove shortcut key from program settings item in Win+X menu +"NoMenuAccelerator"=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 ;x 1 Sign out ;x 16 Sleep @@ -298,11 +310,6 @@ ;x 2 Shut down (default) ;x 4 Restart "Start_PowerButtonAction"=dword:00000002 -;b Show Command Prompt instead of PowerShell in Win+X menu * -"DontUsePowerShellOnWinX"=dword:00000000 -[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher] -;b Remove shortcut key from program settings item in Win+X menu -"NoMenuAccelerator"=dword:00000000 ;T Updates @@ -324,9 +331,8 @@ ;T Advanced -;t Only change these settings if you know what you are doing. You've been warned! [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher] -;b Enable console * +;b Enable console "AllocConsole"=dword:00000000 ;b Dump memory leaks "Memcheck"=dword:00000000 diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index c5cec90..3723e48 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -31,6 +31,9 @@ #define DEFAULT_UPDATE_URL "https://github.com/valinet/ExplorerPatcher/releases/latest/download/" #define TOAST_BUFSIZ 1024 +#define WM_MSG_GUI_SECTION WM_USER + 1 +#define WM_MSG_GUI_SECTION_GET 1 + // This allows compiling with older Windows SDKs as well #ifndef DWMWA_USE_HOSTBACKDROPBRUSH #define DWMWA_USE_HOSTBACKDROPBRUSH 17 // [set] BOOL, Allows the use of host backdrop brushes for the window. diff --git a/ep_setup/ep_setup.c b/ep_setup/ep_setup.c index 3b11235..83d36fd 100644 --- a/ep_setup/ep_setup.c +++ b/ep_setup/ep_setup.c @@ -381,46 +381,50 @@ int WINAPI wWinMain( CloseHandle(sei.hProcess); } - DWORD dwGUIPid = 0; - GetWindowThreadProcessId(FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL), &dwGUIPid); - if (dwGUIPid) + HWND hWnd = FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL); + if (hWnd) { - HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwGUIPid); - if (hProcess) + DWORD dwGUIPid = 0; + GetWindowThreadProcessId(hWnd, &dwGUIPid); + if (dwGUIPid) { - TerminateProcess(hProcess, 0); - CloseHandle(hProcess); - - HKEY hKey = NULL; - DWORD dwSize = 0; - - RegCreateKeyExW( - HKEY_CURRENT_USER, - TEXT(REGPATH), - 0, - NULL, - REG_OPTION_NON_VOLATILE, - KEY_READ | KEY_WOW64_64KEY | KEY_WRITE, - NULL, - &hKey, - NULL - ); - if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwGUIPid); + if (hProcess) { - hKey = NULL; - } - if (hKey) - { - dwSize = TRUE; - RegSetValueExW( - hKey, - TEXT("OpenPropertiesAtNextStart"), + DWORD dwSection = SendMessageW(hWnd, WM_MSG_GUI_SECTION, WM_MSG_GUI_SECTION_GET, 0); + + TerminateProcess(hProcess, 0); + CloseHandle(hProcess); + + HKEY hKey = NULL; + + RegCreateKeyExW( + HKEY_CURRENT_USER, + TEXT(REGPATH), 0, - REG_DWORD, - &dwSize, - sizeof(DWORD) + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ | KEY_WOW64_64KEY | KEY_WRITE, + NULL, + &hKey, + NULL ); - RegCloseKey(hKey); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } + if (hKey) + { + RegSetValueExW( + hKey, + TEXT("OpenPropertiesAtNextStart"), + 0, + REG_DWORD, + &dwSection, + sizeof(DWORD) + ); + RegCloseKey(hKey); + } } } } diff --git a/version.h b/version.h index 5360a40..fe9e456 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define VER_MAJOR 22000 #define VER_MINOR 318 #define VER_BUILD_HI 37 -#define VER_BUILD_LO 4 +#define VER_BUILD_LO 5 #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.318.37.4" -#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.318.37.4" +#define VER_FILE_STRING VALUE "FileVersion", "22000.318.37.5" +#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.318.37.5"