1
0
mirror of https://github.com/valinet/ExplorerPatcher.git synced 2024-09-24 11:38:28 +02:00

Properties can open last used section when starting

This commit is contained in:
Valentin Radu 2021-11-16 07:00:10 +02:00
parent 0a64066724
commit 59d1e452e4
7 changed files with 251 additions and 100 deletions

View File

@ -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) * 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) * Improved some wording in the Properties UI (#377) (.4)
* Added option to show separators between toolbars in the taskbar (#379) (.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 ## 22000.318.36

View File

@ -79,6 +79,62 @@ static HRESULT GUI_AboutProc(
return S_OK; 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) static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
{ {
GUI* _this; GUI* _this;
@ -190,6 +246,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
SetBkMode(hdcPaint, TRANSPARENT); SetBkMode(hdcPaint, TRANSPARENT);
} }
BOOL bWasSpecifiedSectionValid = FALSE;
FILE* f = fmemopen(pRscr, cbRscr, "r"); FILE* f = fmemopen(pRscr, cbRscr, "r");
char* line = malloc(MAX_LINE_LENGTH * sizeof(char)); char* line = malloc(MAX_LINE_LENGTH * sizeof(char));
wchar_t* text = malloc((MAX_LINE_LENGTH + 3) * sizeof(wchar_t)); 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; size_t bufsiz = MAX_LINE_LENGTH, numChRd = 0, tabOrder = 1, currentSection = -1, topAdj = 0;
while ((numChRd = getline(&line, &bufsiz, f)) != -1) 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))) 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 #ifndef USE_PRIVATE_INTERFACES
@ -322,7 +383,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
rcTemp.bottom = rcText.bottom; rcTemp.bottom = rcText.bottom;
if (PtInRect(&rcTemp, pt)) if (PtInRect(&rcTemp, pt))
{ {
_this->section = currentSection + 1; GUI_SetSection(_this, TRUE, currentSection + 1);
InvalidateRect(hwnd, NULL, FALSE); InvalidateRect(hwnd, NULL, FALSE);
} }
} }
@ -790,7 +851,8 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
wchar_t* p = wcschr(name, L'"'); wchar_t* p = wcschr(name, L'"');
if (p) *p = 0; if (p) *p = 0;
HKEY hKey = NULL; 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 dwDisposition;
DWORD dwSize = sizeof(DWORD); DWORD dwSize = sizeof(DWORD);
DWORD value = FALSE; DWORD value = FALSE;
@ -1069,6 +1131,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
{ {
value = !value; value = !value;
} }
if (!wcscmp(name, L"LastSectionInProperties") && wcsstr(section, _T(REGPATH)) && value)
{
value = _this->section + 1;
}
RegSetValueExW( RegSetValueExW(
hKey, hKey,
name, name,
@ -1264,6 +1330,11 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
free(name); free(name);
free(text); free(text);
free(line); free(line);
if (!bWasSpecifiedSectionValid)
{
GUI_SetSection(_this, FALSE, 0);
InvalidateRect(hwnd, NULL, FALSE);
}
SelectObject(hdcPaint, hOldFont); SelectObject(hdcPaint, hOldFont);
if (!hDC) if (!hDC)
@ -1310,9 +1381,70 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
dwMaxHeight, dwMaxHeight,
SWP_NOZORDER | SWP_NOACTIVATE 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; _this->bCalcExtent = FALSE;
InvalidateRect(hwnd, NULL, FALSE); InvalidateRect(hwnd, NULL, FALSE);
} }
EndBufferedPaint(hBufferedPaint, TRUE); EndBufferedPaint(hBufferedPaint, TRUE);
@ -1444,10 +1576,10 @@ static LRESULT CALLBACK GUI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
return 0; return 0;
} }
// this should be determined from the file, but for now it works // 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->tabOrder = 0;
_this->section = wParam - 0x30 - 1; GUI_SetSection(_this, TRUE, wParam - '1');
InvalidateRect(hWnd, NULL, FALSE); InvalidateRect(hWnd, NULL, FALSE);
return 0; return 0;
} }
@ -1515,6 +1647,10 @@ static LRESULT CALLBACK GUI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
EndPaint(hWnd, &ps); EndPaint(hWnd, &ps);
return 0; 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); return DefWindowProc(hWnd, uMsg, wParam, lParam);
} }
@ -1528,7 +1664,6 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin
} }
HKEY hKey = NULL; HKEY hKey = NULL;
DWORD dwDisposition;
DWORD dwSize = sizeof(DWORD); DWORD dwSize = sizeof(DWORD);
RegCreateKeyExW( RegCreateKeyExW(
HKEY_CURRENT_USER, HKEY_CURRENT_USER,
@ -1536,48 +1671,51 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin
0, 0,
NULL, NULL,
REG_OPTION_NON_VOLATILE, REG_OPTION_NON_VOLATILE,
KEY_READ, KEY_READ | KEY_WOW64_64KEY,
NULL, NULL,
&hKey, &hKey,
&dwDisposition NULL
); );
if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) if (hKey == NULL || hKey == INVALID_HANDLE_VALUE)
{ {
hKey = NULL; hKey = NULL;
} }
DWORD bAllocConsole = FALSE; 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) 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]; 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); SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
GUI _this; GUI _this;
ZeroMemory(&_this, sizeof(GUI));
_this.hBackgroundBrush = (HBRUSH)(CreateSolidBrush(RGB(255, 255, 255)));// (HBRUSH)GetStockObject(BLACK_BRUSH); _this.hBackgroundBrush = (HBRUSH)(CreateSolidBrush(RGB(255, 255, 255)));// (HBRUSH)GetStockObject(BLACK_BRUSH);
_this.location.x = GUI_POSITION_X; _this.location.x = GUI_POSITION_X;
_this.location.y = GUI_POSITION_Y; _this.location.y = GUI_POSITION_Y;
@ -1749,6 +1888,10 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin
} }
} }
ShowWindow(hwnd, SW_SHOW); ShowWindow(hwnd, SW_SHOW);
if (hKey)
{
RegCloseKey(hKey);
}
MSG msg = { 0 }; MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) while (GetMessage(&msg, NULL, 0, 0))

View File

@ -3430,16 +3430,9 @@ void WINAPI LoadSettings(BOOL bIsExplorer)
); );
if (dwTemp) if (dwTemp)
{ {
#ifdef _WIN64
LaunchPropertiesGUI(hModule); LaunchPropertiesGUI(hModule);
dwTemp = 0; #endif
RegSetValueExW(
hKey,
TEXT("OpenPropertiesAtNextStart"),
0,
REG_DWORD,
&dwTemp,
sizeof(DWORD)
);
} }
RegCloseKey(hKey); RegCloseKey(hKey);
} }

View File

@ -10,7 +10,7 @@
"OldTaskbar"=dword:00000001 "OldTaskbar"=dword:00000001
;y More taskbar options in the Settings app 🡕 ;y More taskbar options in the Settings app 🡕
;ms-settings:taskbar ;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] [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
;c 3 Combine taskbar icons on main taskbar ;c 3 Combine taskbar icons on main taskbar
;x 0 Always combine ;x 0 Always combine
@ -46,11 +46,13 @@
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher] [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher]
;b Show separators between toolbars * ;b Show separators between toolbars *
"ToolbarSeparators"=dword:00000000 "ToolbarSeparators"=dword:00000000
;b Add shortcut to program settings in Win+X menu ;t
"PropertiesInWinX"=dword:00000000 ;t
;T System tray ;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 ;shell:::{05d7b0f4-2121-4eff-bf6b-ed3f69b894d9}\SystemIcons
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
;b Show seconds in the clock ;b Show seconds in the clock
@ -131,8 +133,8 @@
@="{64bc32b5-4eec-4de7-972d-bd8bd0324537}" @="{64bc32b5-4eec-4de7-972d-bd8bd0324537}"
;t ________________________ ;t ________________________
;e For the settings marked with (**) to work in Open/Save file dialogs as well, register this ;e For the settings marked with (**) to work in Open/Save file dialogs as well, register
;e utility as shell extension using the option above. ;e this utility as shell extension using the option above.
;y Learn more 🡕 ;y Learn more 🡕
;https://github.com/valinet/ExplorerPatcher/wiki/Using-ExplorerPatcher-as-shell-extension ;https://github.com/valinet/ExplorerPatcher/wiki/Using-ExplorerPatcher-as-shell-extension
@ -286,11 +288,21 @@
;T Other ;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 ;b Open clock flyout when pressing Win+C instead of Microsoft Teams
"ClockFlyoutOnWinC"=dword:00000000 "ClockFlyoutOnWinC"=dword:00000000
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] [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 256 Switch user
;x 1 Sign out ;x 1 Sign out
;x 16 Sleep ;x 16 Sleep
@ -298,11 +310,6 @@
;x 2 Shut down (default) ;x 2 Shut down (default)
;x 4 Restart ;x 4 Restart
"Start_PowerButtonAction"=dword:00000002 "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 ;T Updates
@ -324,9 +331,8 @@
;T Advanced ;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] [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ExplorerPatcher]
;b Enable console * ;b Enable console
"AllocConsole"=dword:00000000 "AllocConsole"=dword:00000000
;b Dump memory leaks ;b Dump memory leaks
"Memcheck"=dword:00000000 "Memcheck"=dword:00000000

View File

@ -31,6 +31,9 @@
#define DEFAULT_UPDATE_URL "https://github.com/valinet/ExplorerPatcher/releases/latest/download/" #define DEFAULT_UPDATE_URL "https://github.com/valinet/ExplorerPatcher/releases/latest/download/"
#define TOAST_BUFSIZ 1024 #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 // This allows compiling with older Windows SDKs as well
#ifndef DWMWA_USE_HOSTBACKDROPBRUSH #ifndef DWMWA_USE_HOSTBACKDROPBRUSH
#define DWMWA_USE_HOSTBACKDROPBRUSH 17 // [set] BOOL, Allows the use of host backdrop brushes for the window. #define DWMWA_USE_HOSTBACKDROPBRUSH 17 // [set] BOOL, Allows the use of host backdrop brushes for the window.

View File

@ -381,46 +381,50 @@ int WINAPI wWinMain(
CloseHandle(sei.hProcess); CloseHandle(sei.hProcess);
} }
DWORD dwGUIPid = 0; HWND hWnd = FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL);
GetWindowThreadProcessId(FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL), &dwGUIPid); if (hWnd)
if (dwGUIPid)
{ {
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwGUIPid); DWORD dwGUIPid = 0;
if (hProcess) GetWindowThreadProcessId(hWnd, &dwGUIPid);
if (dwGUIPid)
{ {
TerminateProcess(hProcess, 0); HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwGUIPid);
CloseHandle(hProcess); if (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)
{ {
hKey = NULL; DWORD dwSection = SendMessageW(hWnd, WM_MSG_GUI_SECTION, WM_MSG_GUI_SECTION_GET, 0);
}
if (hKey) TerminateProcess(hProcess, 0);
{ CloseHandle(hProcess);
dwSize = TRUE;
RegSetValueExW( HKEY hKey = NULL;
hKey,
TEXT("OpenPropertiesAtNextStart"), RegCreateKeyExW(
HKEY_CURRENT_USER,
TEXT(REGPATH),
0, 0,
REG_DWORD, NULL,
&dwSize, REG_OPTION_NON_VOLATILE,
sizeof(DWORD) 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);
}
} }
} }
} }

View File

@ -1,7 +1,7 @@
#define VER_MAJOR 22000 #define VER_MAJOR 22000
#define VER_MINOR 318 #define VER_MINOR 318
#define VER_BUILD_HI 37 #define VER_BUILD_HI 37
#define VER_BUILD_LO 4 #define VER_BUILD_LO 5
#define VER_FLAGS VS_FF_PRERELEASE #define VER_FLAGS VS_FF_PRERELEASE
@ -12,5 +12,5 @@
#define VER_STR(arg) #arg #define VER_STR(arg) #arg
// The String form of the version numbers // The String form of the version numbers
#define VER_FILE_STRING VALUE "FileVersion", "22000.318.37.4" #define VER_FILE_STRING VALUE "FileVersion", "22000.318.37.5"
#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.318.37.4" #define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.318.37.5"