Author: akhaldi Date: Sat Mar 14 10:28:22 2015 New Revision: 66681
URL: http://svn.reactos.org/svn/reactos?rev=66681&view=rev Log: [DESK] Set the default value for the placement combobox and load the monitor bitmap before the registry is accessed. Lower the requested access rights for RegOpenKeyEx to HKEY_QUERY_VALUE. In case RegOpenKeyEx fails, simply return to the calling function. Remove result and varType variables. By Ricardo Hanke. CORE-9365
Modified: trunk/reactos/dll/cpl/desk/background.c
Modified: trunk/reactos/dll/cpl/desk/background.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/background.c?r... ============================================================================== --- trunk/reactos/dll/cpl/desk/background.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/desk/background.c [iso-8859-1] Sat Mar 14 10:28:22 2015 @@ -446,8 +446,6 @@ HKEY regKey; TCHAR szBuffer[2]; DWORD bufferSize = sizeof(szBuffer); - DWORD varType = REG_SZ; - LONG result; BITMAP bitmap;
AddListViewItems(hwndDlg, pData); @@ -461,21 +459,25 @@ LoadString(hApplet, IDS_TILE, szString, sizeof(szString) / sizeof(TCHAR)); SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_INSERTSTRING, PLACEMENT_TILE, (LPARAM)szString);
+ SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_SETCURSEL, PLACEMENT_CENTER, 0); + pData->placementSelection = PLACEMENT_CENTER; + + pData->hBitmap = (HBITMAP) LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); + if (pData->hBitmap != NULL) + { + GetObject(pData->hBitmap, sizeof(BITMAP), &bitmap); + + pData->cxSource = bitmap.bmWidth; + pData->cySource = bitmap.bmHeight; + } + /* Load the default settings from the registry */ - result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\Desktop"), 0, KEY_ALL_ACCESS, ®Key); - if (result != ERROR_SUCCESS) - { - /* reg key open failed; maybe it does not exist? create it! */ - DWORD dwDisposition = 0; - result = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\Desktop"), 0, NULL, 0, KEY_ALL_ACCESS, NULL, - ®Key, &dwDisposition ); - /* Now the key must be created & opened and regKey points to opened key */ - /* On error result will not contain ERROR_SUCCESS. I don't know how to handle */ - /* this case :( */ - } - - result = RegQueryValueEx(regKey, TEXT("WallpaperStyle"), 0, &varType, (LPBYTE)szBuffer, &bufferSize); - if (result == ERROR_SUCCESS) + if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\Desktop"), 0, KEY_QUERY_VALUE, ®Key) != ERROR_SUCCESS) + { + return; + } + + if (RegQueryValueEx(regKey, TEXT("WallpaperStyle"), 0, NULL, (LPBYTE)szBuffer, &bufferSize) == ERROR_SUCCESS) { if (_ttoi(szBuffer) == 0) { @@ -489,14 +491,8 @@ pData->placementSelection = PLACEMENT_STRETCH; } } - else - { - SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_SETCURSEL, PLACEMENT_CENTER, 0); - pData->placementSelection = PLACEMENT_CENTER; - } - - result = RegQueryValueEx(regKey, TEXT("TileWallpaper"), 0, &varType, (LPBYTE)szBuffer, &bufferSize); - if (result == ERROR_SUCCESS) + + if (RegQueryValueEx(regKey, TEXT("TileWallpaper"), 0, NULL, (LPBYTE)szBuffer, &bufferSize) == ERROR_SUCCESS) { if (_ttoi(szBuffer) == 1) { @@ -506,15 +502,6 @@ }
RegCloseKey(regKey); - - pData->hBitmap = (HBITMAP) LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); - if (pData->hBitmap != NULL) - { - GetObject(pData->hBitmap, sizeof(BITMAP), &bitmap); - - pData->cxSource = bitmap.bmWidth; - pData->cySource = bitmap.bmHeight; - } }