[MSPAINT] refactor RegistrySettings::SetWallpaper, also changing its signature to make it more usable

svn path=/trunk/; revision=73055
This commit is contained in:
Benedikt Freisen 2016-10-28 19:48:25 +00:00
parent 85f275a284
commit 3d592530f4
3 changed files with 13 additions and 15 deletions

View file

@ -35,23 +35,15 @@ static void ReadFileHistory(CRegKey &key, LPCTSTR lpName, CString &strFile)
strFile.ReleaseBuffer(); strFile.ReleaseBuffer();
} }
void RegistrySettings::SetWallpaper(LPCTSTR szFileName, DWORD dwStyle, DWORD dwTile) void RegistrySettings::SetWallpaper(LPCTSTR szFileName, RegistrySettings::WallpaperStyle style)
{ {
if ((dwStyle > 2) || (dwTile > 2))
return;
CRegKey desktop; CRegKey desktop;
if (desktop.Open(HKEY_CURRENT_USER, _T("Control Panel\\Desktop")) == ERROR_SUCCESS) if (desktop.Open(HKEY_CURRENT_USER, _T("Control Panel\\Desktop")) == ERROR_SUCCESS)
{ {
CString strStyle, strTile;
desktop.SetStringValue(_T("Wallpaper"), szFileName); desktop.SetStringValue(_T("Wallpaper"), szFileName);
strStyle.Format(_T("%lu"), dwStyle); desktop.SetStringValue(_T("WallpaperStyle"), (style == RegistrySettings::STRETCHED) ? _T("2") : _T("1"));
strTile.Format(_T("%lu"), dwTile); desktop.SetStringValue(_T("TileWallpaper"), (style == RegistrySettings::TILED) ? _T("1") : _T("0"));
desktop.SetStringValue(_T("WallpaperStyle"), strStyle);
desktop.SetStringValue(_T("TileWallpaper"), strTile);
} }
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) szFileName, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) szFileName, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);

View file

@ -30,7 +30,13 @@ public:
CString strFile3; CString strFile3;
CString strFile4; CString strFile4;
static void SetWallpaper(LPCTSTR szFileName, DWORD dwStyle, DWORD dwTile); enum WallpaperStyle {
TILED,
CENTERED,
STRETCHED
};
static void SetWallpaper(LPCTSTR szFileName, WallpaperStyle style);
void Load(); void Load();
void Store(); void Store();

View file

@ -451,13 +451,13 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
GlobalFree(pd.hDevNames); GlobalFree(pd.hDevNames);
break; break;
case IDM_FILEASWALLPAPERPLANE: case IDM_FILEASWALLPAPERPLANE:
RegistrySettings::SetWallpaper(filepathname, 1, 1); RegistrySettings::SetWallpaper(filepathname, RegistrySettings::TILED);
break; break;
case IDM_FILEASWALLPAPERCENTERED: case IDM_FILEASWALLPAPERCENTERED:
RegistrySettings::SetWallpaper(filepathname, 1, 0); RegistrySettings::SetWallpaper(filepathname, RegistrySettings::CENTERED);
break; break;
case IDM_FILEASWALLPAPERSTRETCHED: case IDM_FILEASWALLPAPERSTRETCHED:
RegistrySettings::SetWallpaper(filepathname, 2, 0); RegistrySettings::SetWallpaper(filepathname, RegistrySettings::STRETCHED);
break; break;
case IDM_FILE1: case IDM_FILE1:
{ {