[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();
}
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;
if (desktop.Open(HKEY_CURRENT_USER, _T("Control Panel\\Desktop")) == ERROR_SUCCESS)
{
CString strStyle, strTile;
desktop.SetStringValue(_T("Wallpaper"), szFileName);
strStyle.Format(_T("%lu"), dwStyle);
strTile.Format(_T("%lu"), dwTile);
desktop.SetStringValue(_T("WallpaperStyle"), strStyle);
desktop.SetStringValue(_T("TileWallpaper"), strTile);
desktop.SetStringValue(_T("WallpaperStyle"), (style == RegistrySettings::STRETCHED) ? _T("2") : _T("1"));
desktop.SetStringValue(_T("TileWallpaper"), (style == RegistrySettings::TILED) ? _T("1") : _T("0"));
}
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) szFileName, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);

View file

@ -30,7 +30,13 @@ public:
CString strFile3;
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 Store();

View file

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