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