From b5d96da32f955357b7d9341ee9fca68108078dce Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 12 Nov 2012 16:35:05 +0100 Subject: [PATCH] user32: Add helper functions to get and set dword registry values in SystemParametersInfo. --- dlls/user32/sysparams.c | 122 +++++++++++++----------------- dlls/user32/tests/sysparams.c | 137 ++++++++++++++++++++++++++++------ 2 files changed, 166 insertions(+), 93 deletions(-) diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 0fad03b074..26b2c8bb8f 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -615,7 +615,7 @@ static void SYSPARAMS_NotifyChange( UINT uiAction, UINT fWinIni ) /*********************************************************************** * Loads system parameter from user profile. */ -static BOOL SYSPARAMS_LoadRaw( LPCWSTR lpRegKey, LPCWSTR lpValName, LPBYTE lpBuf, DWORD count ) +static BOOL SYSPARAMS_LoadRaw( LPCWSTR lpRegKey, LPCWSTR lpValName, void *lpBuf, DWORD count ) { BOOL ret = FALSE; DWORD type; @@ -649,7 +649,7 @@ static BOOL SYSPARAMS_Load( LPCWSTR lpRegKey, LPCWSTR lpValName, LPWSTR lpBuf, D /* Save data as-is */ static BOOL SYSPARAMS_SaveRaw( LPCWSTR lpRegKey, LPCWSTR lpValName, - const BYTE* lpValue, DWORD valueSize, + const void *lpValue, DWORD valueSize, DWORD type, UINT fWinIni ) { HKEY hKey; @@ -847,6 +847,22 @@ static inline BOOL get_bool_param( unsigned int idx, LPCWSTR regkey, LPCWSTR val return get_uint_param( idx, regkey, value, (UINT *)value_ptr, (UINT *)ret_ptr ); } +/* load a dword (binary) parameter from the registry */ +static BOOL get_dword_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value, + DWORD *value_ptr, DWORD *ret_ptr ) +{ + if (!ret_ptr) return FALSE; + if (!spi_loaded[idx]) + { + DWORD val; + + if (SYSPARAMS_LoadRaw( regkey, value, &val, sizeof(val) )) *value_ptr = val; + spi_loaded[idx] = TRUE; + } + *ret_ptr = *value_ptr; + return TRUE; +} + /* set a uint parameter that is mirrored in two different registry locations */ static BOOL set_uint_param_mirrored( unsigned int idx, LPCWSTR regkey, LPCWSTR regkey_mirror, LPCWSTR value, UINT *value_ptr, UINT new_val, UINT fWinIni ) @@ -904,6 +920,19 @@ static inline BOOL set_bool_param( unsigned int idx, LPCWSTR regkey, LPCWSTR val return set_uint_param( idx, regkey, value, (UINT *)value_ptr, new_val, fWinIni ); } +/* set a dword (binary) parameter in the registry */ +static BOOL set_dword_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value, + DWORD *value_ptr, DWORD new_val, UINT fWinIni ) +{ + BOOL ret = SYSPARAMS_SaveRaw( regkey, value, &new_val, sizeof(new_val), REG_DWORD, fWinIni ); + if (ret) + { + *value_ptr = new_val; + spi_loaded[idx] = TRUE; + } + return ret; +} + /* load a boolean parameter from the user preference key */ static BOOL get_user_pref_param( UINT offset, UINT mask, BOOL *ret_ptr ) { @@ -2418,62 +2447,31 @@ BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam, WINE_SPI_FIXME(SPI_GETMOUSECLICKLOCKTIME); /* 0x2008 _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */ WINE_SPI_FIXME(SPI_SETMOUSECLICKLOCKTIME); /* 0x2009 _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */ case SPI_GETFONTSMOOTHINGTYPE: /* 0x200A _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */ - spi_idx = SPI_SETFONTSMOOTHINGTYPE_IDX; - if (!spi_loaded[spi_idx]) - { - ret = SYSPARAMS_Load( SPI_SETFONTSMOOTHINGTYPE_REGKEY, - SPI_SETFONTSMOOTHINGTYPE_VALNAME, - (LPWSTR)&font_smoothing_type, - sizeof(font_smoothing_type) ); - if ( ret) spi_loaded[spi_idx] = TRUE; - } - if (!pvParam) ret = FALSE; - - if (ret) - *(UINT *)pvParam = font_smoothing_type; + ret = get_dword_param( SPI_SETFONTSMOOTHINGTYPE_IDX, + SPI_SETFONTSMOOTHINGTYPE_REGKEY, + SPI_SETFONTSMOOTHINGTYPE_VALNAME, + &font_smoothing_type, pvParam ); break; case SPI_SETFONTSMOOTHINGTYPE: /* 0x200B _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */ - spi_idx = SPI_SETFONTSMOOTHINGTYPE_IDX; - if (SYSPARAMS_SaveRaw( SPI_SETFONTSMOOTHINGTYPE_REGKEY, + ret = set_dword_param( SPI_SETFONTSMOOTHINGTYPE_IDX, + SPI_SETFONTSMOOTHINGTYPE_REGKEY, SPI_SETFONTSMOOTHINGTYPE_VALNAME, - (LPBYTE)&pvParam, sizeof(UINT), REG_DWORD, fWinIni )) - { - font_smoothing_type = PtrToUlong(pvParam); - spi_loaded[spi_idx] = TRUE; - } - else - ret = FALSE; + &font_smoothing_type, PtrToUlong(pvParam), fWinIni ); break; case SPI_GETFONTSMOOTHINGCONTRAST: /* 0x200C _WIN32_WINNT >= 0x510 */ - spi_idx = SPI_SETFONTSMOOTHINGCONTRAST_IDX; - if (!spi_loaded[spi_idx]) - { - ret = SYSPARAMS_Load( SPI_SETFONTSMOOTHINGCONTRAST_REGKEY, - SPI_SETFONTSMOOTHINGCONTRAST_VALNAME, - (LPWSTR)&font_smoothing_contrast, - sizeof(font_smoothing_contrast) ); - if (ret) - spi_loaded[spi_idx] = TRUE; - } - if (!pvParam) ret = FALSE; - - if (ret) - *(UINT *)pvParam = font_smoothing_contrast; + ret = get_dword_param( SPI_SETFONTSMOOTHINGCONTRAST_IDX, + SPI_SETFONTSMOOTHINGCONTRAST_REGKEY, + SPI_SETFONTSMOOTHINGCONTRAST_VALNAME, + &font_smoothing_contrast, pvParam ); break; case SPI_SETFONTSMOOTHINGCONTRAST: /* 0x200D _WIN32_WINNT >= 0x510 */ - spi_idx = SPI_SETFONTSMOOTHINGCONTRAST_IDX; - if (SYSPARAMS_SaveRaw( SPI_SETFONTSMOOTHINGCONTRAST_REGKEY, + ret = set_dword_param( SPI_SETFONTSMOOTHINGCONTRAST_IDX, + SPI_SETFONTSMOOTHINGCONTRAST_REGKEY, SPI_SETFONTSMOOTHINGCONTRAST_VALNAME, - (LPBYTE)&pvParam, sizeof(UINT), REG_DWORD, fWinIni )) - { - font_smoothing_contrast = PtrToUlong(pvParam); - spi_loaded[spi_idx] = TRUE; - } - else - ret = FALSE; + &font_smoothing_contrast, PtrToUlong(pvParam), fWinIni ); break; case SPI_GETFOCUSBORDERWIDTH: /* 0x200E _WIN32_WINNT >= 0x510 */ @@ -2488,33 +2486,17 @@ BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam, WINE_SPI_FIXME(SPI_SETFOCUSBORDERHEIGHT); /* 0x2011 _WIN32_WINNT >= 0x510 */ case SPI_GETFONTSMOOTHINGORIENTATION: /* 0x2012 */ - spi_idx = SPI_SETFONTSMOOTHINGORIENTATION_IDX; - if (!spi_loaded[spi_idx]) - { - ret = SYSPARAMS_Load( SPI_SETFONTSMOOTHINGORIENTATION_REGKEY, - SPI_SETFONTSMOOTHINGORIENTATION_VALNAME, - (LPWSTR)&font_smoothing_orientation, - sizeof(font_smoothing_orientation) ); - if (ret) - spi_loaded[spi_idx] = TRUE; - } - if (!pvParam) ret = FALSE; - - if (ret) - *(UINT *)pvParam = font_smoothing_orientation; + ret = get_dword_param( SPI_SETFONTSMOOTHINGORIENTATION_IDX, + SPI_SETFONTSMOOTHINGORIENTATION_REGKEY, + SPI_SETFONTSMOOTHINGORIENTATION_VALNAME, + &font_smoothing_orientation, pvParam ); break; case SPI_SETFONTSMOOTHINGORIENTATION: /* 0x2013 */ - spi_idx = SPI_SETFONTSMOOTHINGORIENTATION_IDX; - if (SYSPARAMS_SaveRaw( SPI_SETFONTSMOOTHINGORIENTATION_REGKEY, + ret = set_dword_param( SPI_SETFONTSMOOTHINGORIENTATION_IDX, + SPI_SETFONTSMOOTHINGORIENTATION_REGKEY, SPI_SETFONTSMOOTHINGORIENTATION_VALNAME, - (LPBYTE)&pvParam, sizeof(UINT), REG_DWORD, fWinIni )) - { - font_smoothing_orientation = PtrToUlong(pvParam); - spi_loaded[spi_idx] = TRUE; - } - else - ret = FALSE; + &font_smoothing_orientation, PtrToUlong(pvParam), fWinIni ); break; default: diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c index b641f6be60..ad43cb71be 100644 --- a/dlls/user32/tests/sysparams.c +++ b/dlls/user32/tests/sysparams.c @@ -125,6 +125,9 @@ static HDC hdc; #define SPI_SETSCREENREADER_VALNAME_LEGACY "Blind Access" #define SPI_SETFONTSMOOTHING_REGKEY "Control Panel\\Desktop" #define SPI_SETFONTSMOOTHING_VALNAME "FontSmoothing" +#define SPI_SETFONTSMOOTHINGTYPE_VALNAME "FontSmoothingType" +#define SPI_SETFONTSMOOTHINGCONTRAST_VALNAME "FontSmoothingGamma" +#define SPI_SETFONTSMOOTHINGORIENTATION_VALNAME "FontSmoothingOrientation" #define SPI_SETLOWPOWERACTIVE_REGKEY "Control Panel\\Desktop" #define SPI_SETLOWPOWERACTIVE_VALNAME "LowPowerActive" #define SPI_SETPOWEROFFACTIVE_REGKEY "Control Panel\\Desktop" @@ -269,13 +272,9 @@ static BOOL test_error_msg ( int rc, const char *name ) /* * Tests the HKEY_CURRENT_USER subkey value. * The value should contain string value. - * - * Params: - * lpsSubKey - subkey name - * lpsRegName - registry entry name - * lpsTestValue - value to test */ -static void _test_reg_key( LPCSTR subKey1, LPCSTR subKey2, LPCSTR valName1, LPCSTR valName2, LPCSTR testValue, BOOL optional ) +static void _test_reg_key( LPCSTR subKey1, LPCSTR subKey2, LPCSTR valName1, LPCSTR valName2, + const void *exp_value, DWORD exp_type, BOOL optional ) { CHAR value[MAX_PATH]; DWORD valueLen; @@ -291,9 +290,20 @@ static void _test_reg_key( LPCSTR subKey1, LPCSTR subKey2, LPCSTR valName1, LPCS RegCloseKey( hKey ); if (rc==ERROR_SUCCESS) { - ok( !strcmp( testValue, value ), - "Wrong value in registry: subKey=%s, valName=%s, testValue=%s, value=%s\n", - subKey1, valName1, testValue, value ); + ok( type == exp_type, "wrong type %u/%u\n", type, exp_type ); + switch (exp_type) + { + case REG_DWORD: + ok( *(DWORD *)value == *(DWORD *)exp_value, + "Wrong value in registry: %s %s %08x/%08x\n", + subKey1, valName1, *(DWORD *)value, *(DWORD *)exp_value ); + break; + case REG_SZ: + ok( !strcmp( exp_value, value ), + "Wrong value in registry: %s %s '%s' instead of '%s'\n", + subKey1, valName1, value, (const char *)exp_value ); + break; + } found++; } else if (strict) @@ -310,9 +320,20 @@ static void _test_reg_key( LPCSTR subKey1, LPCSTR subKey2, LPCSTR valName1, LPCS RegCloseKey( hKey ); if (rc==ERROR_SUCCESS) { - ok( !strcmp( testValue, value ), - "Wrong value in registry: subKey=%s, valName=%s, testValue=%s, value=%s\n", - subKey1, valName2, testValue, value ); + ok( type == exp_type, "wrong type %u/%u\n", type, exp_type ); + switch (exp_type) + { + case REG_DWORD: + ok( *(DWORD *)value == *(DWORD *)exp_value, + "Wrong value in registry: %s %s %08x/%08x\n", + subKey1, valName1, *(DWORD *)value, *(DWORD *)exp_value ); + break; + case REG_SZ: + ok( !strcmp( exp_value, value ), + "Wrong value in registry: %s %s '%s' instead of '%s'\n", + subKey1, valName1, value, (const char *)exp_value ); + break; + } found++; } else if (strict) @@ -330,9 +351,20 @@ static void _test_reg_key( LPCSTR subKey1, LPCSTR subKey2, LPCSTR valName1, LPCS RegCloseKey( hKey ); if (rc==ERROR_SUCCESS) { - ok( !strcmp( testValue, value ), - "Wrong value in registry: subKey=%s, valName=%s, testValue=%s, value=%s\n", - subKey2, valName1, testValue, value ); + ok( type == exp_type, "wrong type %u/%u\n", type, exp_type ); + switch (exp_type) + { + case REG_DWORD: + ok( *(DWORD *)value == *(DWORD *)exp_value, + "Wrong value in registry: %s %s %08x/%08x\n", + subKey1, valName1, *(DWORD *)value, *(DWORD *)exp_value ); + break; + case REG_SZ: + ok( !strcmp( exp_value, value ), + "Wrong value in registry: %s %s '%s' instead of '%s'\n", + subKey1, valName1, value, (const char *)exp_value ); + break; + } found++; } else if (strict) @@ -349,9 +381,20 @@ static void _test_reg_key( LPCSTR subKey1, LPCSTR subKey2, LPCSTR valName1, LPCS RegCloseKey( hKey ); if (rc==ERROR_SUCCESS) { - ok( !strcmp( testValue, value ), - "Wrong value in registry: subKey=%s, valName=%s, testValue=%s, value=%s\n", - subKey2, valName2, testValue, value ); + ok( type == exp_type, "wrong type %u/%u\n", type, exp_type ); + switch (exp_type) + { + case REG_DWORD: + ok( *(DWORD *)value == *(DWORD *)exp_value, + "Wrong value in registry: %s %s %08x/%08x\n", + subKey1, valName1, *(DWORD *)value, *(DWORD *)exp_value ); + break; + case REG_SZ: + ok( !strcmp( exp_value, value ), + "Wrong value in registry: %s %s '%s' instead of '%s'\n", + subKey1, valName1, value, (const char *)exp_value ); + break; + } found++; } else if (strict) @@ -367,15 +410,17 @@ static void _test_reg_key( LPCSTR subKey1, LPCSTR subKey2, LPCSTR valName1, LPCS } #define test_reg_key( subKey, valName, testValue ) \ - _test_reg_key( subKey, NULL, valName, NULL, testValue, FALSE ) + _test_reg_key( subKey, NULL, valName, NULL, testValue, REG_SZ, FALSE ) #define test_reg_key_optional( subKey, valName, testValue ) \ - _test_reg_key( subKey, NULL, valName, NULL, testValue, TRUE ) + _test_reg_key( subKey, NULL, valName, NULL, testValue, REG_SZ, TRUE ) #define test_reg_key_ex( subKey1, subKey2, valName, testValue ) \ - _test_reg_key( subKey1, subKey2, valName, NULL, testValue, FALSE ) + _test_reg_key( subKey1, subKey2, valName, NULL, testValue, REG_SZ, FALSE ) #define test_reg_key_ex2( subKey1, subKey2, valName1, valName2, testValue ) \ - _test_reg_key( subKey1, subKey2, valName1, valName2, testValue, FALSE ) + _test_reg_key( subKey1, subKey2, valName1, valName2, testValue, REG_SZ, FALSE ) #define test_reg_key_ex2_optional( subKey1, subKey2, valName1, valName2, testValue ) \ - _test_reg_key( subKey1, subKey2, valName1, valName2, testValue, TRUE ) + _test_reg_key( subKey1, subKey2, valName1, valName2, testValue, REG_SZ, TRUE ) +#define test_reg_key_dword( subKey, valName, testValue ) \ + _test_reg_key( subKey, NULL, valName, NULL, testValue, REG_DWORD, FALSE ) /* get a metric from the registry. If the value is negative * it is assumed to be in twips and converted to pixels */ @@ -1941,6 +1986,7 @@ static void test_SPI_SETFONTSMOOTHING( void ) /* 75 */ { BOOL rc; BOOL old_b; + DWORD old_type, old_contrast, old_orient; const UINT vals[]={0xffffffff,0,1,2}; unsigned int i; @@ -1950,6 +1996,9 @@ static void test_SPI_SETFONTSMOOTHING( void ) /* 75 */ rc=SystemParametersInfoA( SPI_GETFONTSMOOTHING, 0, &old_b, 0 ); if (!test_error_msg(rc,"SPI_{GET,SET}FONTSMOOTHING")) return; + SystemParametersInfoA( SPI_GETFONTSMOOTHINGTYPE, 0, &old_type, 0 ); + SystemParametersInfoA( SPI_GETFONTSMOOTHINGCONTRAST, 0, &old_contrast, 0 ); + SystemParametersInfoA( SPI_GETFONTSMOOTHINGORIENTATION, 0, &old_orient, 0 ); for (i=0;i