2015-05-08 16:02:36 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/mspaint/registry.cpp
|
2015-05-08 16:02:36 +00:00
|
|
|
* PURPOSE: Offering functions dealing with registry values
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
2020-02-14 02:05:21 +00:00
|
|
|
* Katayama Hirofumi MZ
|
2015-05-08 16:02:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
#include <winreg.h>
|
2020-02-14 02:05:21 +00:00
|
|
|
#include <wincon.h>
|
|
|
|
#include <shlobj.h>
|
2015-05-08 16:02:36 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
2016-10-01 20:04:43 +00:00
|
|
|
static DWORD ReadDWORD(CRegKey &key, LPCTSTR lpName, DWORD &dwValue, BOOL bCheckForDef)
|
2016-08-08 14:00:18 +00:00
|
|
|
{
|
2016-10-01 20:04:43 +00:00
|
|
|
DWORD dwPrev = dwValue;
|
2016-08-08 14:00:18 +00:00
|
|
|
|
2021-06-30 22:08:33 +00:00
|
|
|
if (key.QueryDWORDValue(lpName, dwValue) != ERROR_SUCCESS || (bCheckForDef && dwValue == 0))
|
2016-10-01 20:04:43 +00:00
|
|
|
dwValue = dwPrev;
|
2016-08-08 14:00:18 +00:00
|
|
|
|
|
|
|
return dwPrev;
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
static void ReadFileHistory(CRegKey &key, LPCTSTR lpName, CString &strFile)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2016-10-01 20:04:43 +00:00
|
|
|
ULONG nChars = MAX_PATH;
|
|
|
|
LPTSTR szFile = strFile.GetBuffer(nChars);
|
|
|
|
if (key.QueryStringValue(lpName, szFile, &nChars) != ERROR_SUCCESS)
|
|
|
|
szFile[0] = '\0';
|
|
|
|
strFile.ReleaseBuffer();
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2016-10-28 19:48:25 +00:00
|
|
|
void RegistrySettings::SetWallpaper(LPCTSTR szFileName, RegistrySettings::WallpaperStyle style)
|
2016-10-01 20:04:43 +00:00
|
|
|
{
|
|
|
|
CRegKey desktop;
|
|
|
|
if (desktop.Open(HKEY_CURRENT_USER, _T("Control Panel\\Desktop")) == ERROR_SUCCESS)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2016-10-01 20:04:43 +00:00
|
|
|
desktop.SetStringValue(_T("Wallpaper"), szFileName);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2017-05-28 17:33:15 +00:00
|
|
|
desktop.SetStringValue(_T("WallpaperStyle"), (style == RegistrySettings::STRETCHED) ? _T("2") : _T("0"));
|
2016-10-28 19:48:25 +00:00
|
|
|
desktop.SetStringValue(_T("TileWallpaper"), (style == RegistrySettings::TILED) ? _T("1") : _T("0"));
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2016-10-15 11:44:15 +00:00
|
|
|
|
2019-04-28 19:19:42 +00:00
|
|
|
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) szFileName, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-08-16 19:52:37 +00:00
|
|
|
|
|
|
|
void RegistrySettings::LoadPresets()
|
|
|
|
{
|
|
|
|
BMPHeight = 300;
|
|
|
|
BMPWidth = 400;
|
|
|
|
GridExtent = 1;
|
|
|
|
NoStretching = 0;
|
|
|
|
ShowThumbnail = 0;
|
|
|
|
SnapToGrid = 0;
|
|
|
|
ThumbHeight = 100;
|
|
|
|
ThumbWidth = 120;
|
|
|
|
ThumbXPos = 180;
|
|
|
|
ThumbYPos = 200;
|
|
|
|
UnitSetting = 0;
|
|
|
|
const WINDOWPLACEMENT DefaultWindowPlacement = {
|
2021-09-13 01:33:14 +00:00
|
|
|
sizeof(WINDOWPLACEMENT),
|
2015-08-16 19:52:37 +00:00
|
|
|
0,
|
|
|
|
SW_SHOWNORMAL,
|
|
|
|
{0, 0},
|
|
|
|
{-1, -1},
|
|
|
|
{100, 100, 700, 550}
|
|
|
|
};
|
|
|
|
WindowPlacement = DefaultWindowPlacement;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegistrySettings::Load()
|
|
|
|
{
|
|
|
|
LoadPresets();
|
2016-10-01 20:04:43 +00:00
|
|
|
|
|
|
|
CRegKey view;
|
|
|
|
if (view.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), KEY_READ) == ERROR_SUCCESS)
|
2015-08-16 19:52:37 +00:00
|
|
|
{
|
2016-10-01 20:04:43 +00:00
|
|
|
ReadDWORD(view, _T("BMPHeight"), BMPHeight, TRUE);
|
|
|
|
ReadDWORD(view, _T("BMPWidth"), BMPWidth, TRUE);
|
|
|
|
ReadDWORD(view, _T("GridExtent"), GridExtent, FALSE);
|
|
|
|
ReadDWORD(view, _T("NoStretching"), NoStretching, FALSE);
|
|
|
|
ReadDWORD(view, _T("ShowThumbnail"), ShowThumbnail, FALSE);
|
|
|
|
ReadDWORD(view, _T("SnapToGrid"), SnapToGrid, FALSE);
|
|
|
|
ReadDWORD(view, _T("ThumbHeight"), ThumbHeight, TRUE);
|
|
|
|
ReadDWORD(view, _T("ThumbWidth"), ThumbWidth, TRUE);
|
|
|
|
ReadDWORD(view, _T("ThumbXPos"), ThumbXPos, TRUE);
|
|
|
|
ReadDWORD(view, _T("ThumbYPos"), ThumbYPos, TRUE);
|
|
|
|
ReadDWORD(view, _T("UnitSetting"), UnitSetting, FALSE);
|
|
|
|
|
|
|
|
ULONG pnBytes = sizeof(WINDOWPLACEMENT);
|
|
|
|
view.QueryBinaryValue(_T("WindowPlacement"), &WindowPlacement, &pnBytes);
|
2015-08-16 19:52:37 +00:00
|
|
|
}
|
2016-09-26 19:53:42 +00:00
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
CRegKey files;
|
|
|
|
if (files.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), KEY_READ) == ERROR_SUCCESS)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
2016-10-01 20:04:43 +00:00
|
|
|
ReadFileHistory(files, _T("File1"), strFile1);
|
|
|
|
ReadFileHistory(files, _T("File2"), strFile2);
|
|
|
|
ReadFileHistory(files, _T("File3"), strFile3);
|
|
|
|
ReadFileHistory(files, _T("File4"), strFile4);
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
2015-08-16 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegistrySettings::Store()
|
|
|
|
{
|
2016-10-01 20:04:43 +00:00
|
|
|
CRegKey view;
|
|
|
|
if (view.Create(HKEY_CURRENT_USER,
|
|
|
|
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View")) == ERROR_SUCCESS)
|
2015-08-16 19:52:37 +00:00
|
|
|
{
|
2016-10-01 20:04:43 +00:00
|
|
|
view.SetDWORDValue(_T("BMPHeight"), BMPHeight);
|
|
|
|
view.SetDWORDValue(_T("BMPWidth"), BMPWidth);
|
|
|
|
view.SetDWORDValue(_T("GridExtent"), GridExtent);
|
|
|
|
view.SetDWORDValue(_T("NoStretching"), NoStretching);
|
|
|
|
view.SetDWORDValue(_T("ShowThumbnail"), ShowThumbnail);
|
|
|
|
view.SetDWORDValue(_T("SnapToGrid"), SnapToGrid);
|
|
|
|
view.SetDWORDValue(_T("ThumbHeight"), ThumbHeight);
|
|
|
|
view.SetDWORDValue(_T("ThumbWidth"), ThumbWidth);
|
|
|
|
view.SetDWORDValue(_T("ThumbXPos"), ThumbXPos);
|
|
|
|
view.SetDWORDValue(_T("ThumbYPos"), ThumbYPos);
|
|
|
|
view.SetDWORDValue(_T("UnitSetting"), UnitSetting);
|
|
|
|
|
|
|
|
view.SetBinaryValue(_T("WindowPlacement"), &WindowPlacement, sizeof(WINDOWPLACEMENT));
|
2015-08-16 19:52:37 +00:00
|
|
|
}
|
2016-09-26 19:53:42 +00:00
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
CRegKey files;
|
|
|
|
if (files.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List")) == ERROR_SUCCESS)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
|
|
|
if (!strFile1.IsEmpty())
|
2016-10-01 20:04:43 +00:00
|
|
|
files.SetStringValue(_T("File1"), strFile1);
|
2016-09-26 19:53:42 +00:00
|
|
|
if (!strFile2.IsEmpty())
|
2016-10-01 20:04:43 +00:00
|
|
|
files.SetStringValue(_T("File2"), strFile2);
|
2016-09-26 19:53:42 +00:00
|
|
|
if (!strFile3.IsEmpty())
|
2016-10-01 20:04:43 +00:00
|
|
|
files.SetStringValue(_T("File3"), strFile3);
|
2016-09-26 19:53:42 +00:00
|
|
|
if (!strFile4.IsEmpty())
|
2016-10-01 20:04:43 +00:00
|
|
|
files.SetStringValue(_T("File4"), strFile4);
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
void RegistrySettings::SetMostRecentFile(LPCTSTR szPathName)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
2020-02-14 02:05:21 +00:00
|
|
|
if (szPathName && szPathName[0])
|
|
|
|
SHAddToRecentDocs(SHARD_PATHW, szPathName);
|
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
if (strFile1 == szPathName)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
2016-10-01 20:04:43 +00:00
|
|
|
else if (strFile2 == szPathName)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
|
|
|
CString strTemp = strFile2;
|
|
|
|
strFile2 = strFile1;
|
|
|
|
strFile1 = strTemp;
|
|
|
|
}
|
2016-10-01 20:04:43 +00:00
|
|
|
else if (strFile3 == szPathName)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
|
|
|
CString strTemp = strFile3;
|
|
|
|
strFile3 = strFile2;
|
|
|
|
strFile2 = strFile1;
|
|
|
|
strFile1 = strTemp;
|
|
|
|
}
|
2016-10-01 20:04:43 +00:00
|
|
|
else if (strFile4 == szPathName)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
|
|
|
CString strTemp = strFile4;
|
|
|
|
strFile4 = strFile3;
|
|
|
|
strFile3 = strFile2;
|
|
|
|
strFile2 = strFile1;
|
|
|
|
strFile1 = strTemp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strFile4 = strFile3;
|
|
|
|
strFile3 = strFile2;
|
|
|
|
strFile2 = strFile1;
|
2016-10-01 20:04:43 +00:00
|
|
|
strFile1 = szPathName;
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
2015-08-16 19:52:37 +00:00
|
|
|
}
|