18 changed files with 1726 additions and 867 deletions
@ -1,336 +1,64 @@ |
|||||||
#include "SettingsMonitor.h" |
#include "SettingsMonitor.h" |
||||||
|
|
||||||
DWORD MonitorSettingsChanges(SettingsChangeParameters* params) |
DWORD MonitorSettings(SettingsChangeParameters* params) |
||||||
{ |
{ |
||||||
HMODULE hModule = LoadLibraryW(L"Shlwapi.dll"); |
while (TRUE) |
||||||
if (hModule) |
{ |
||||||
{ |
HANDLE* handles = malloc(sizeof(HANDLE) * params->size); |
||||||
FARPROC SHRegGetValueFromHKCUHKLMFunc = GetProcAddress(hModule, "SHRegGetValueFromHKCUHKLM"); |
if (!handles) |
||||||
DWORD dwSize = sizeof(DWORD); |
{ |
||||||
LONG lRes = ERROR_SUCCESS; |
return 0; |
||||||
HKEY hKeyCU, hKeyLM; |
} |
||||||
|
for (unsigned int i = 0; i < params->size; ++i) |
||||||
dwSize = sizeof(DWORD); |
{ |
||||||
DWORD dwInitialTaskbarAl = 0, dwTaskbarAl = 0, dwInitialTaskbarAlWas = 0; |
params->settings[i].hEvent = CreateEventW(NULL, FALSE, FALSE, NULL); |
||||||
if (!SHRegGetValueFromHKCUHKLMFunc || SHRegGetValueFromHKCUHKLMFunc( |
if (!params->settings[i].hEvent) |
||||||
TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), |
{ |
||||||
TEXT("TaskbarAl"), |
return 0; |
||||||
SRRF_RT_REG_DWORD, |
} |
||||||
NULL, |
handles[i] = params->settings[i].hEvent; |
||||||
&dwInitialTaskbarAl, |
if (RegCreateKeyExW( |
||||||
(LPDWORD)(&dwSize) |
params->settings[i].origin, |
||||||
) != ERROR_SUCCESS) |
params->settings[i].name, |
||||||
{ |
0, |
||||||
dwInitialTaskbarAl = 0; |
NULL, |
||||||
} |
REG_OPTION_NON_VOLATILE, |
||||||
else |
KEY_READ, |
||||||
{ |
NULL, |
||||||
dwInitialTaskbarAlWas = 1; |
&(params->settings[i].hKey), |
||||||
} |
NULL |
||||||
|
) != ERROR_SUCCESS) |
||||||
dwSize = sizeof(DWORD); |
{ |
||||||
DWORD dwInitialMaximumFrequentApps = 6, dwMaximumFrequentApps = 6, dwInitialMaximumFrequentAppsWas = 0; |
return 0; |
||||||
if (!SHRegGetValueFromHKCUHKLMFunc || SHRegGetValueFromHKCUHKLMFunc( |
} |
||||||
TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), |
if (RegNotifyChangeKeyValue( |
||||||
TEXT("Start_MaximumFrequentApps"), |
params->settings[i].hKey, |
||||||
SRRF_RT_REG_DWORD, |
FALSE, |
||||||
NULL, |
REG_NOTIFY_CHANGE_LAST_SET, |
||||||
&dwInitialMaximumFrequentApps, |
params->settings[i].hEvent, |
||||||
(LPDWORD)(&dwSize) |
TRUE |
||||||
) != ERROR_SUCCESS) |
) != ERROR_SUCCESS) |
||||||
{ |
{ |
||||||
dwInitialMaximumFrequentApps = 6; |
return 0; |
||||||
} |
} |
||||||
else |
} |
||||||
{ |
DWORD dwRes = WaitForMultipleObjects( |
||||||
dwInitialMaximumFrequentAppsWas = 1; |
params->size, |
||||||
} |
handles, |
||||||
|
FALSE, |
||||||
while (TRUE) |
INFINITE |
||||||
{ |
); |
||||||
lRes = RegOpenKeyExW( |
if (dwRes != WAIT_FAILED) |
||||||
HKEY_CURRENT_USER, |
{ |
||||||
TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), |
unsigned int i = dwRes - WAIT_OBJECT_0; |
||||||
0, |
params->settings[i].callback(params->settings[i].data); |
||||||
KEY_READ, |
} |
||||||
&hKeyCU |
free(handles); |
||||||
); |
for (unsigned int i = 0; i < params->size; ++i) |
||||||
if (hKeyCU == NULL || hKeyCU == INVALID_HANDLE_VALUE) |
{ |
||||||
{ |
CloseHandle(params->settings[i].hEvent); |
||||||
hKeyCU = NULL; |
RegCloseKey(params->settings[i].hKey); |
||||||
} |
} |
||||||
if (lRes != ERROR_SUCCESS) |
} |
||||||
{ |
|
||||||
return 0; |
|
||||||
} |
|
||||||
HANDLE hEvHKCU = CreateEvent(NULL, FALSE, FALSE, NULL); |
|
||||||
if (hEvHKCU == NULL || hEvHKCU == INVALID_HANDLE_VALUE) |
|
||||||
{ |
|
||||||
hEvHKCU = NULL; |
|
||||||
return 0; |
|
||||||
} |
|
||||||
RegNotifyChangeKeyValue( |
|
||||||
hKeyCU, |
|
||||||
FALSE, |
|
||||||
REG_NOTIFY_CHANGE_LAST_SET, |
|
||||||
hEvHKCU, |
|
||||||
TRUE |
|
||||||
); |
|
||||||
|
|
||||||
lRes = RegOpenKeyExW( |
|
||||||
HKEY_LOCAL_MACHINE, |
|
||||||
TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), |
|
||||||
0, |
|
||||||
KEY_READ, |
|
||||||
&hKeyLM |
|
||||||
); |
|
||||||
if (hKeyLM == NULL || hKeyLM == INVALID_HANDLE_VALUE) |
|
||||||
{ |
|
||||||
hKeyLM = NULL; |
|
||||||
} |
|
||||||
if (lRes != ERROR_SUCCESS) |
|
||||||
{ |
|
||||||
return 0; |
|
||||||
} |
|
||||||
HANDLE hEvHKLM = CreateEvent(NULL, FALSE, FALSE, NULL); |
|
||||||
if (hEvHKLM == NULL || hEvHKLM == INVALID_HANDLE_VALUE) |
|
||||||
{ |
|
||||||
hEvHKLM = NULL; |
|
||||||
return 0; |
|
||||||
} |
|
||||||
RegNotifyChangeKeyValue( |
|
||||||
hKeyLM, |
|
||||||
FALSE, |
|
||||||
REG_NOTIFY_CHANGE_LAST_SET, |
|
||||||
hEvHKLM, |
|
||||||
TRUE |
|
||||||
); |
|
||||||
printf("!!! Setup monitor %d %d\n", hEvHKCU, hEvHKLM); |
|
||||||
|
|
||||||
HANDLE hEvents[2]; |
|
||||||
hEvents[0] = hEvHKCU; |
|
||||||
hEvents[1] = hEvHKLM; |
|
||||||
DWORD rv = WaitForMultipleObjects( |
|
||||||
2, |
|
||||||
hEvents, |
|
||||||
FALSE, |
|
||||||
INFINITE |
|
||||||
); |
|
||||||
if (rv == WAIT_OBJECT_0) |
|
||||||
{ |
|
||||||
dwSize = sizeof(DWORD); |
|
||||||
lRes = RegQueryValueExW( |
|
||||||
hKeyCU, |
|
||||||
TEXT("TaskbarAl"), |
|
||||||
0, |
|
||||||
NULL, |
|
||||||
&dwTaskbarAl, |
|
||||||
&dwSize |
|
||||||
); |
|
||||||
if (lRes != ERROR_SUCCESS && dwInitialTaskbarAlWas) |
|
||||||
{ |
|
||||||
if (params->TaskbarAlChangedCallback) |
|
||||||
{ |
|
||||||
void* p = 0; |
|
||||||
if (params->TaskbarAlChangedCallbackData) |
|
||||||
{ |
|
||||||
p = params->TaskbarAlChangedCallbackData; |
|
||||||
} |
|
||||||
params->TaskbarAlChangedCallback(p, dwTaskbarAl); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
exit(0); |
|
||||||
} |
|
||||||
dwInitialTaskbarAl = dwTaskbarAl; |
|
||||||
} |
|
||||||
if (lRes == ERROR_SUCCESS && dwTaskbarAl != dwInitialTaskbarAl) |
|
||||||
{ |
|
||||||
if (params->TaskbarAlChangedCallback) |
|
||||||
{ |
|
||||||
void* p = 0; |
|
||||||
if (params->TaskbarAlChangedCallbackData) |
|
||||||
{ |
|
||||||
p = params->TaskbarAlChangedCallbackData; |
|
||||||
} |
|
||||||
params->TaskbarAlChangedCallback(p, dwTaskbarAl); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
exit(0); |
|
||||||
} |
|
||||||
dwInitialTaskbarAl = dwTaskbarAl; |
|
||||||
} |
|
||||||
|
|
||||||
if (params->isStartMenuExperienceHost) |
|
||||||
{ |
|
||||||
dwSize = sizeof(DWORD); |
|
||||||
lRes = RegQueryValueExW( |
|
||||||
hKeyCU, |
|
||||||
TEXT("Start_MaximumFrequentApps"), |
|
||||||
0, |
|
||||||
NULL, |
|
||||||
&dwMaximumFrequentApps, |
|
||||||
&dwSize |
|
||||||
); |
|
||||||
if (lRes != ERROR_SUCCESS && dwInitialMaximumFrequentAppsWas) |
|
||||||
{ |
|
||||||
if (params->Start_MaximumRecentAppsChangedCallback) |
|
||||||
{ |
|
||||||
void* p = 0; |
|
||||||
if (params->Start_MaximumRecentAppsChangedCallbackData) |
|
||||||
{ |
|
||||||
p = params->Start_MaximumRecentAppsChangedCallbackData; |
|
||||||
} |
|
||||||
params->Start_MaximumRecentAppsChangedCallback(p, dwMaximumFrequentApps); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
exit(0); |
|
||||||
} |
|
||||||
dwInitialMaximumFrequentApps = dwMaximumFrequentApps; |
|
||||||
} |
|
||||||
if (lRes == ERROR_SUCCESS && dwMaximumFrequentApps != dwInitialMaximumFrequentApps) |
|
||||||
{ |
|
||||||
if (params->Start_MaximumRecentAppsChangedCallback) |
|
||||||
{ |
|
||||||
void* p = 0; |
|
||||||
if (params->Start_MaximumRecentAppsChangedCallbackData) |
|
||||||
{ |
|
||||||
p = params->Start_MaximumRecentAppsChangedCallbackData; |
|
||||||
} |
|
||||||
params->Start_MaximumRecentAppsChangedCallback(p, dwMaximumFrequentApps); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
exit(0); |
|
||||||
} |
|
||||||
dwInitialMaximumFrequentApps = dwMaximumFrequentApps; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
else if (rv == WAIT_OBJECT_0 + 1) |
|
||||||
{ |
|
||||||
dwSize = sizeof(DWORD); |
|
||||||
lRes = RegQueryValueExW( |
|
||||||
hKeyCU, |
|
||||||
TEXT("TaskbarAl"), |
|
||||||
0, |
|
||||||
NULL, |
|
||||||
&dwTaskbarAl, |
|
||||||
&dwSize |
|
||||||
); |
|
||||||
if (lRes != ERROR_SUCCESS) |
|
||||||
{ |
|
||||||
dwSize = sizeof(DWORD); |
|
||||||
lRes = RegQueryValueExW( |
|
||||||
hKeyLM, |
|
||||||
TEXT("TaskbarAl"), |
|
||||||
0, |
|
||||||
NULL, |
|
||||||
&dwTaskbarAl, |
|
||||||
&dwSize |
|
||||||
); |
|
||||||
if (lRes != ERROR_SUCCESS && dwInitialTaskbarAlWas) |
|
||||||
{ |
|
||||||
if (params->TaskbarAlChangedCallback) |
|
||||||
{ |
|
||||||
void* p = 0; |
|
||||||
if (params->TaskbarAlChangedCallbackData) |
|
||||||
{ |
|
||||||
p = params->TaskbarAlChangedCallbackData; |
|
||||||
} |
|
||||||
params->TaskbarAlChangedCallback(p, dwTaskbarAl); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
exit(0); |
|
||||||
} |
|
||||||
dwInitialTaskbarAl = dwTaskbarAl; |
|
||||||
} |
|
||||||
if (lRes == ERROR_SUCCESS && dwTaskbarAl != dwInitialTaskbarAl) |
|
||||||
{ |
|
||||||
if (params->TaskbarAlChangedCallback) |
|
||||||
{ |
|
||||||
void* p = 0; |
|
||||||
if (params->TaskbarAlChangedCallbackData) |
|
||||||
{ |
|
||||||
p = params->TaskbarAlChangedCallbackData; |
|
||||||
} |
|
||||||
params->TaskbarAlChangedCallback(p, dwTaskbarAl); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
exit(0); |
|
||||||
} |
|
||||||
dwInitialTaskbarAl = dwTaskbarAl; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (params->isStartMenuExperienceHost) |
|
||||||
{ |
|
||||||
dwSize = sizeof(DWORD); |
|
||||||
lRes = RegQueryValueExW( |
|
||||||
hKeyCU, |
|
||||||
TEXT("Start_MaximumFrequentApps"), |
|
||||||
0, |
|
||||||
NULL, |
|
||||||
&dwMaximumFrequentApps, |
|
||||||
&dwSize |
|
||||||
); |
|
||||||
if (lRes != ERROR_SUCCESS) |
|
||||||
{ |
|
||||||
dwSize = sizeof(DWORD); |
|
||||||
lRes = RegQueryValueExW( |
|
||||||
hKeyLM, |
|
||||||
TEXT("Start_MaximumFrequentApps"), |
|
||||||
0, |
|
||||||
NULL, |
|
||||||
&dwMaximumFrequentApps, |
|
||||||
&dwSize |
|
||||||
); |
|
||||||
if (lRes != ERROR_SUCCESS && dwInitialMaximumFrequentAppsWas) |
|
||||||
{ |
|
||||||
if (params->Start_MaximumRecentAppsChangedCallback) |
|
||||||
{ |
|
||||||
void* p = 0; |
|
||||||
if (params->Start_MaximumRecentAppsChangedCallbackData) |
|
||||||
{ |
|
||||||
p = params->Start_MaximumRecentAppsChangedCallbackData; |
|
||||||
} |
|
||||||
params->Start_MaximumRecentAppsChangedCallback(p, dwMaximumFrequentApps); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
exit(0); |
|
||||||
} |
|
||||||
dwInitialMaximumFrequentApps = dwMaximumFrequentApps; |
|
||||||
} |
|
||||||
if (lRes == ERROR_SUCCESS && dwMaximumFrequentApps != dwInitialMaximumFrequentApps) |
|
||||||
{ |
|
||||||
if (params->Start_MaximumRecentAppsChangedCallback) |
|
||||||
{ |
|
||||||
void* p = 0; |
|
||||||
if (params->Start_MaximumRecentAppsChangedCallbackData) |
|
||||||
{ |
|
||||||
p = params->Start_MaximumRecentAppsChangedCallbackData; |
|
||||||
} |
|
||||||
params->Start_MaximumRecentAppsChangedCallback(p, dwMaximumFrequentApps); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
exit(0); |
|
||||||
} |
|
||||||
dwInitialMaximumFrequentApps = dwMaximumFrequentApps; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (hEvHKCU) CloseHandle(hEvHKCU); |
|
||||||
if (hEvHKLM) CloseHandle(hEvHKLM); |
|
||||||
if (hKeyCU) RegCloseKey(hKeyCU); |
|
||||||
if (hKeyLM) RegCloseKey(hKeyLM); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
Loading…
Reference in new issue