mirror of
https://github.com/reactos/reactos.git
synced 2025-05-25 12:14:32 +00:00
[DESK.CPL]
- Only use the minimum required registry rights needed in RegOpenKeyEx and RegCreateKeyEx calls. - Fix SetDesktopBackColor function where we tried to save the selected desktop background color in the registry only in the case where opening the corresponding registry key actually failed... >_> Now we do the right thing! svn path=/trunk/; revision=71443
This commit is contained in:
parent
cc1a5a5932
commit
2047efde02
1 changed files with 41 additions and 37 deletions
|
@ -179,7 +179,6 @@ AddWallpapersFromDirectory(UINT uCounter, HWND hwndBackgroundList, BackgroundIte
|
|||
LV_ITEM listItem;
|
||||
HIMAGELIST himl;
|
||||
|
||||
|
||||
szFileTypes = GdipGetSupportedFileExtensions();
|
||||
if (!szFileTypes)
|
||||
{
|
||||
|
@ -216,7 +215,6 @@ AddWallpapersFromDirectory(UINT uCounter, HWND hwndBackgroundList, BackgroundIte
|
|||
sizeof(sfi),
|
||||
SHGFI_SYSICONINDEX | SHGFI_SMALLICON |
|
||||
SHGFI_DISPLAYNAME);
|
||||
|
||||
if (himl == NULL)
|
||||
break;
|
||||
|
||||
|
@ -332,7 +330,7 @@ AddListViewItems(HWND hwndDlg, PDATA pData)
|
|||
pData->listViewItemCount++;
|
||||
|
||||
/* Add current wallpaper if any */
|
||||
result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS, ®Key);
|
||||
result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_QUERY_VALUE, ®Key);
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
result = RegQueryValueEx(regKey, TEXT("Wallpaper"), 0, &varType, (LPBYTE)wallpaperFilename, &bufferSize);
|
||||
|
@ -376,7 +374,6 @@ AddListViewItems(HWND hwndDlg, PDATA pData)
|
|||
sizeof(sfi),
|
||||
SHGFI_SYSICONINDEX | SHGFI_SMALLICON |
|
||||
SHGFI_DISPLAYNAME);
|
||||
|
||||
if (himl != NULL)
|
||||
{
|
||||
if (i++ == 0)
|
||||
|
@ -513,8 +510,8 @@ OnColorButton(HWND hwndDlg, PDATA pData)
|
|||
LONG res = ERROR_SUCCESS;
|
||||
CHOOSECOLOR cc;
|
||||
|
||||
res = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance"), 0, NULL, 0,
|
||||
KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
||||
res = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance"), 0, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE, NULL, &hKey, NULL);
|
||||
/* Now the key is either created or opened existing, if res == ERROR_SUCCESS */
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
|
@ -522,7 +519,7 @@ OnColorButton(HWND hwndDlg, PDATA pData)
|
|||
DWORD dwType = REG_BINARY;
|
||||
DWORD cbData = sizeof(pData->custom_colors);
|
||||
res = RegQueryValueEx(hKey, TEXT("CustomColors"), NULL, &dwType,
|
||||
(LPBYTE)pData->custom_colors, &cbData);
|
||||
(LPBYTE)pData->custom_colors, &cbData);
|
||||
RegCloseKey(hKey);
|
||||
hKey = NULL;
|
||||
}
|
||||
|
@ -554,12 +551,12 @@ OnColorButton(HWND hwndDlg, PDATA pData)
|
|||
|
||||
/* Save custom colors to reg. To this moment key must be created already. See above */
|
||||
res = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance"), 0,
|
||||
KEY_WRITE, &hKey);
|
||||
KEY_SET_VALUE, &hKey);
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
/* Key opened */
|
||||
RegSetValueEx(hKey, TEXT("CustomColors"), 0, REG_BINARY,
|
||||
(const BYTE *)pData->custom_colors, sizeof(pData->custom_colors));
|
||||
(LPBYTE)pData->custom_colors, sizeof(pData->custom_colors));
|
||||
RegCloseKey(hKey);
|
||||
hKey = NULL;
|
||||
}
|
||||
|
@ -907,7 +904,6 @@ SetWallpaper(PDATA pData)
|
|||
size_t length = 0;
|
||||
GpStatus status;
|
||||
|
||||
|
||||
if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, szWallpaper)))
|
||||
{
|
||||
return;
|
||||
|
@ -918,24 +914,28 @@ SetWallpaper(PDATA pData)
|
|||
return;
|
||||
}
|
||||
|
||||
RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS, ®Key);
|
||||
if (RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, ®Key, NULL) != ERROR_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (pData->placementSelection == PLACEMENT_TILE)
|
||||
{
|
||||
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE *)TEXT("1"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE *)TEXT("0"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (LPBYTE)TEXT("1"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (LPBYTE)TEXT("0"), sizeof(TCHAR) * 2);
|
||||
}
|
||||
|
||||
if (pData->placementSelection == PLACEMENT_CENTER)
|
||||
{
|
||||
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE *)TEXT("0"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE *)TEXT("0"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (LPBYTE)TEXT("0"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (LPBYTE)TEXT("0"), sizeof(TCHAR) * 2);
|
||||
}
|
||||
|
||||
if (pData->placementSelection == PLACEMENT_STRETCH)
|
||||
{
|
||||
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE *)TEXT("0"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE *)TEXT("2"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (LPBYTE)TEXT("0"), sizeof(TCHAR) * 2);
|
||||
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (LPBYTE)TEXT("2"), sizeof(TCHAR) * 2);
|
||||
}
|
||||
|
||||
if (pData->backgroundItems[pData->backgroundSelection].bWallpaper == TRUE)
|
||||
|
@ -979,7 +979,7 @@ SetWallpaper(PDATA pData)
|
|||
TEXT("ConvertedWallpaper"),
|
||||
0,
|
||||
REG_SZ,
|
||||
(BYTE*)pData->backgroundItems[pData->backgroundSelection].szFilename,
|
||||
(LPBYTE)pData->backgroundItems[pData->backgroundSelection].szFilename,
|
||||
(DWORD)((length + 1) * sizeof(TCHAR)));
|
||||
}
|
||||
|
||||
|
@ -989,7 +989,7 @@ SetWallpaper(PDATA pData)
|
|||
TEXT("OriginalWallpaper"),
|
||||
0,
|
||||
REG_SZ,
|
||||
(BYTE *)szWallpaper,
|
||||
(LPBYTE)szWallpaper,
|
||||
(DWORD)((length + 1) * sizeof(TCHAR)));
|
||||
}
|
||||
|
||||
|
@ -1008,30 +1008,34 @@ SetWallpaper(PDATA pData)
|
|||
static VOID
|
||||
SetDesktopBackColor(HWND hwndDlg, DATA *pData)
|
||||
{
|
||||
INT iElement = COLOR_BACKGROUND;
|
||||
HKEY hKey;
|
||||
LONG result;
|
||||
INT iElement = COLOR_BACKGROUND;
|
||||
TCHAR clText[16];
|
||||
BYTE red, green, blue;
|
||||
DWORD dwDispostion;
|
||||
|
||||
if( !SetSysColors( 1, &iElement, &g_GlobalData.desktop_color ) )
|
||||
MessageBox(hwndDlg, TEXT("SetSysColor() failed!"), /* these error texts can need internationalization? */
|
||||
TEXT("Error!"), MB_ICONSTOP );
|
||||
|
||||
result = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\\Colors"), 0, NULL, 0,
|
||||
KEY_ALL_ACCESS, NULL, &hKey, &dwDispostion );
|
||||
if (result != ERROR_SUCCESS)
|
||||
if (!SetSysColors(1, &iElement, &g_GlobalData.desktop_color))
|
||||
{
|
||||
red = GetRValue(g_GlobalData.desktop_color);
|
||||
green = GetGValue(g_GlobalData.desktop_color);
|
||||
blue = GetBValue(g_GlobalData.desktop_color);
|
||||
/* Format string to be set to registry */
|
||||
StringCbPrintf(clText, sizeof(clText), TEXT("%d %d %d"), red, green, blue);
|
||||
RegSetValueEx(hKey, TEXT("Background"), 0, REG_SZ, (BYTE *)clText,
|
||||
(lstrlen(clText) + 1) * sizeof(TCHAR));
|
||||
RegCloseKey(hKey);
|
||||
/* FIXME: these error texts can need internationalization? */
|
||||
MessageBox(hwndDlg, TEXT("SetSysColor() failed!"),
|
||||
TEXT("Error!"), MB_ICONSTOP );
|
||||
}
|
||||
|
||||
if (RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Colors"), 0, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL) != ERROR_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
red = GetRValue(g_GlobalData.desktop_color);
|
||||
green = GetGValue(g_GlobalData.desktop_color);
|
||||
blue = GetBValue(g_GlobalData.desktop_color);
|
||||
|
||||
/* Format string to be set to registry */
|
||||
StringCbPrintf(clText, sizeof(clText), TEXT("%d %d %d"), red, green, blue);
|
||||
RegSetValueEx(hKey, TEXT("Background"), 0, REG_SZ, (LPBYTE)clText,
|
||||
(wcslen(clText) + 1) * sizeof(TCHAR));
|
||||
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK
|
||||
|
|
Loading…
Reference in a new issue