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
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
2023-03-28 13:31:26 +00:00
|
|
|
RegistrySettings registrySettings;
|
|
|
|
|
2015-05-08 16:02:36 +00:00
|
|
|
/* FUNCTIONS ********************************************************/
|
2023-03-28 13:31:26 +00:00
|
|
|
|
2023-03-18 08:12:28 +00:00
|
|
|
static void ReadDWORD(CRegKey &key, LPCTSTR lpName, DWORD &dwValue)
|
2016-08-08 14:00:18 +00:00
|
|
|
{
|
2023-03-18 08:12:28 +00:00
|
|
|
DWORD dwTemp;
|
|
|
|
if (key.QueryDWORDValue(lpName, dwTemp) == ERROR_SUCCESS)
|
|
|
|
dwValue = dwTemp;
|
2016-08-08 14:00:18 +00:00
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2022-01-05 07:26:05 +00:00
|
|
|
static void ReadString(CRegKey &key, LPCTSTR lpName, CString &strValue, LPCTSTR lpDefault = TEXT(""))
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2022-01-05 07:26:05 +00:00
|
|
|
CString strTemp;
|
2016-10-01 20:04:43 +00:00
|
|
|
ULONG nChars = MAX_PATH;
|
2022-01-05 07:26:05 +00:00
|
|
|
LPTSTR psz = strTemp.GetBuffer(nChars);
|
|
|
|
LONG error = key.QueryStringValue(lpName, psz, &nChars);
|
|
|
|
strTemp.ReleaseBuffer();
|
|
|
|
|
|
|
|
if (error == ERROR_SUCCESS)
|
|
|
|
strValue = strTemp;
|
|
|
|
else
|
|
|
|
strValue = lpDefault;
|
2016-10-01 20:04:43 +00:00
|
|
|
}
|
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
|
|
|
|
2023-03-16 22:26:44 +00:00
|
|
|
void RegistrySettings::LoadPresets(INT nCmdShow)
|
2015-08-16 19:52:37 +00:00
|
|
|
{
|
2021-12-27 01:52:53 +00:00
|
|
|
BMPHeight = GetSystemMetrics(SM_CYSCREEN) / 2;
|
|
|
|
BMPWidth = GetSystemMetrics(SM_CXSCREEN) / 2;
|
2015-08-16 19:52:37 +00:00
|
|
|
GridExtent = 1;
|
|
|
|
NoStretching = 0;
|
|
|
|
ShowThumbnail = 0;
|
|
|
|
SnapToGrid = 0;
|
|
|
|
ThumbHeight = 100;
|
|
|
|
ThumbWidth = 120;
|
|
|
|
ThumbXPos = 180;
|
|
|
|
ThumbYPos = 200;
|
|
|
|
UnitSetting = 0;
|
2022-01-05 07:26:05 +00:00
|
|
|
Bold = FALSE;
|
|
|
|
Italic = FALSE;
|
|
|
|
Underline = FALSE;
|
|
|
|
CharSet = DEFAULT_CHARSET;
|
|
|
|
PointSize = 14;
|
|
|
|
FontsPositionX = 0;
|
|
|
|
FontsPositionY = 0;
|
|
|
|
ShowTextTool = TRUE;
|
2023-03-11 02:41:52 +00:00
|
|
|
ShowStatusBar = TRUE;
|
2023-03-18 08:12:28 +00:00
|
|
|
ShowPalette = TRUE;
|
2023-03-18 08:19:56 +00:00
|
|
|
ShowToolBox = TRUE;
|
2023-04-04 10:06:06 +00:00
|
|
|
Bar1ID = BAR1ID_TOP;
|
2023-04-03 05:34:56 +00:00
|
|
|
Bar2ID = BAR2ID_LEFT;
|
2022-01-05 07:26:05 +00:00
|
|
|
|
|
|
|
LOGFONT lf;
|
|
|
|
GetObject(GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf);
|
|
|
|
strFontName = lf.lfFaceName;
|
|
|
|
|
|
|
|
ZeroMemory(&WindowPlacement, sizeof(WindowPlacement));
|
2023-03-16 22:26:44 +00:00
|
|
|
RECT& rc = WindowPlacement.rcNormalPosition;
|
|
|
|
rc.left = rc.top = CW_USEDEFAULT;
|
|
|
|
rc.right = rc.left + 544;
|
|
|
|
rc.bottom = rc.top + 375;
|
|
|
|
WindowPlacement.showCmd = nCmdShow;
|
2015-08-16 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2023-03-16 22:26:44 +00:00
|
|
|
void RegistrySettings::Load(INT nCmdShow)
|
2015-08-16 19:52:37 +00:00
|
|
|
{
|
2023-03-16 22:26:44 +00:00
|
|
|
LoadPresets(nCmdShow);
|
2016-10-01 20:04:43 +00:00
|
|
|
|
2023-03-18 08:12:28 +00:00
|
|
|
CRegKey paint;
|
|
|
|
if (paint.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint"), KEY_READ) != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
CRegKey view;
|
2023-03-18 08:12:28 +00:00
|
|
|
if (view.Open(paint, _T("View"), KEY_READ) == ERROR_SUCCESS)
|
2015-08-16 19:52:37 +00:00
|
|
|
{
|
2023-03-18 08:12:28 +00:00
|
|
|
ReadDWORD(view, _T("BMPHeight"), BMPHeight);
|
|
|
|
ReadDWORD(view, _T("BMPWidth"), BMPWidth);
|
|
|
|
ReadDWORD(view, _T("GridExtent"), GridExtent);
|
|
|
|
ReadDWORD(view, _T("NoStretching"), NoStretching);
|
|
|
|
ReadDWORD(view, _T("ShowThumbnail"), ShowThumbnail);
|
|
|
|
ReadDWORD(view, _T("SnapToGrid"), SnapToGrid);
|
|
|
|
ReadDWORD(view, _T("ThumbHeight"), ThumbHeight);
|
|
|
|
ReadDWORD(view, _T("ThumbWidth"), ThumbWidth);
|
|
|
|
ReadDWORD(view, _T("ThumbXPos"), ThumbXPos);
|
|
|
|
ReadDWORD(view, _T("ThumbYPos"), ThumbYPos);
|
|
|
|
ReadDWORD(view, _T("UnitSetting"), UnitSetting);
|
|
|
|
ReadDWORD(view, _T("ShowStatusBar"), ShowStatusBar);
|
2016-10-01 20:04:43 +00:00
|
|
|
|
|
|
|
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;
|
2023-03-18 08:12:28 +00:00
|
|
|
if (files.Open(paint, _T("Recent File List"), KEY_READ) == ERROR_SUCCESS)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
2023-03-16 22:28:01 +00:00
|
|
|
TCHAR szName[64];
|
|
|
|
for (INT i = 0; i < MAX_RECENT_FILES; ++i)
|
|
|
|
{
|
|
|
|
wsprintf(szName, _T("File%u"), i + 1);
|
|
|
|
ReadString(files, szName, strFiles[i]);
|
|
|
|
}
|
2022-01-05 07:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CRegKey text;
|
2023-03-18 08:12:28 +00:00
|
|
|
if (text.Open(paint, _T("Text"), KEY_READ) == ERROR_SUCCESS)
|
2022-01-05 07:26:05 +00:00
|
|
|
{
|
2023-03-18 08:12:28 +00:00
|
|
|
ReadDWORD(text, _T("Bold"), Bold);
|
|
|
|
ReadDWORD(text, _T("Italic"), Italic);
|
|
|
|
ReadDWORD(text, _T("Underline"), Underline);
|
|
|
|
ReadDWORD(text, _T("CharSet"), CharSet);
|
|
|
|
ReadDWORD(text, _T("PointSize"), PointSize);
|
|
|
|
ReadDWORD(text, _T("PositionX"), FontsPositionX);
|
|
|
|
ReadDWORD(text, _T("PositionY"), FontsPositionY);
|
|
|
|
ReadDWORD(text, _T("ShowTextTool"), ShowTextTool);
|
2022-01-05 07:26:05 +00:00
|
|
|
ReadString(text, _T("TypeFaceName"), strFontName, strFontName);
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
2021-12-27 01:52:53 +00:00
|
|
|
|
2023-04-04 10:06:06 +00:00
|
|
|
CRegKey bar1;
|
|
|
|
if (bar1.Open(paint, _T("General-Bar1"), KEY_READ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ReadDWORD(bar1, _T("BarID"), Bar1ID);
|
|
|
|
}
|
|
|
|
|
2023-04-03 05:34:56 +00:00
|
|
|
CRegKey bar2;
|
|
|
|
if (bar2.Open(paint, _T("General-Bar2"), KEY_READ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ReadDWORD(bar2, _T("BarID"), Bar2ID);
|
|
|
|
}
|
|
|
|
|
2023-03-18 08:19:56 +00:00
|
|
|
CRegKey bar3;
|
|
|
|
if (bar3.Open(paint, _T("General-Bar3"), KEY_READ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ReadDWORD(bar3, _T("Visible"), ShowToolBox);
|
|
|
|
}
|
|
|
|
|
2023-03-18 08:12:28 +00:00
|
|
|
CRegKey bar4;
|
|
|
|
if (bar4.Open(paint, _T("General-Bar4"), KEY_READ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ReadDWORD(bar4, _T("Visible"), ShowPalette);
|
|
|
|
}
|
|
|
|
|
2021-12-27 01:52:53 +00:00
|
|
|
// Fix the bitmap size if too large
|
|
|
|
if (BMPWidth > 5000)
|
|
|
|
BMPWidth = (GetSystemMetrics(SM_CXSCREEN) * 6) / 10;
|
|
|
|
if (BMPHeight > 5000)
|
|
|
|
BMPHeight = (GetSystemMetrics(SM_CYSCREEN) * 6) / 10;
|
2015-08-16 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegistrySettings::Store()
|
|
|
|
{
|
2023-03-28 13:31:26 +00:00
|
|
|
BMPWidth = imageModel.GetWidth();
|
|
|
|
BMPHeight = imageModel.GetHeight();
|
|
|
|
|
2023-03-18 08:12:28 +00:00
|
|
|
CRegKey paint;
|
|
|
|
if (paint.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint")) != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
CRegKey view;
|
2023-03-18 08:12:28 +00:00
|
|
|
if (view.Create(paint, _T("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);
|
2023-03-11 02:41:52 +00:00
|
|
|
view.SetDWORDValue(_T("ShowStatusBar"), ShowStatusBar);
|
2016-10-01 20:04:43 +00:00
|
|
|
|
|
|
|
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;
|
2023-03-18 08:12:28 +00:00
|
|
|
if (files.Create(paint, _T("Recent File List")) == ERROR_SUCCESS)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
2023-03-16 22:28:01 +00:00
|
|
|
TCHAR szName[64];
|
|
|
|
for (INT iFile = 0; iFile < MAX_RECENT_FILES; ++iFile)
|
|
|
|
{
|
|
|
|
wsprintf(szName, _T("File%u"), iFile + 1);
|
|
|
|
files.SetStringValue(szName, strFiles[iFile]);
|
|
|
|
}
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
2022-01-05 07:26:05 +00:00
|
|
|
|
|
|
|
CRegKey text;
|
2023-03-18 08:12:28 +00:00
|
|
|
if (text.Create(paint, _T("Text")) == ERROR_SUCCESS)
|
2022-01-05 07:26:05 +00:00
|
|
|
{
|
|
|
|
text.SetDWORDValue(_T("Bold"), Bold);
|
|
|
|
text.SetDWORDValue(_T("Italic"), Italic);
|
|
|
|
text.SetDWORDValue(_T("Underline"), Underline);
|
|
|
|
text.SetDWORDValue(_T("CharSet"), CharSet);
|
|
|
|
text.SetDWORDValue(_T("PointSize"), PointSize);
|
|
|
|
text.SetDWORDValue(_T("PositionX"), FontsPositionX);
|
|
|
|
text.SetDWORDValue(_T("PositionY"), FontsPositionY);
|
|
|
|
text.SetDWORDValue(_T("ShowTextTool"), ShowTextTool);
|
|
|
|
text.SetStringValue(_T("TypeFaceName"), strFontName);
|
|
|
|
}
|
2023-03-18 08:12:28 +00:00
|
|
|
|
2023-04-04 10:06:06 +00:00
|
|
|
CRegKey bar1;
|
|
|
|
if (bar1.Create(paint, _T("General-Bar1")) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
bar1.SetDWORDValue(_T("BarID"), Bar1ID);
|
|
|
|
}
|
|
|
|
|
2023-04-03 05:34:56 +00:00
|
|
|
CRegKey bar2;
|
|
|
|
if (bar2.Create(paint, _T("General-Bar2")) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
bar2.SetDWORDValue(_T("BarID"), Bar2ID);
|
|
|
|
}
|
|
|
|
|
2023-03-18 08:19:56 +00:00
|
|
|
CRegKey bar3;
|
|
|
|
if (bar3.Create(paint, _T("General-Bar3")) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
bar3.SetDWORDValue(_T("Visible"), ShowToolBox);
|
|
|
|
}
|
|
|
|
|
2023-03-18 08:12:28 +00:00
|
|
|
CRegKey bar4;
|
|
|
|
if (bar4.Create(paint, _T("General-Bar4")) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
bar4.SetDWORDValue(_T("Visible"), ShowPalette);
|
|
|
|
}
|
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
|
|
|
{
|
2023-03-16 22:28:01 +00:00
|
|
|
// Register the file to the user's 'Recent' folder
|
2020-02-14 02:05:21 +00:00
|
|
|
if (szPathName && szPathName[0])
|
|
|
|
SHAddToRecentDocs(SHARD_PATHW, szPathName);
|
|
|
|
|
2023-03-16 22:28:01 +00:00
|
|
|
// If szPathName is present in strFiles, move it to the top of the list
|
|
|
|
for (INT i = MAX_RECENT_FILES - 1, iFound = -1; i > 0; --i)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
2023-03-16 22:28:01 +00:00
|
|
|
if (iFound < 0 && strFiles[i].CompareNoCase(szPathName) == 0)
|
|
|
|
iFound = i;
|
|
|
|
|
|
|
|
if (iFound >= 0)
|
|
|
|
{
|
|
|
|
CString tmp = strFiles[i];
|
|
|
|
strFiles[i] = strFiles[i - 1];
|
|
|
|
strFiles[i - 1] = tmp;
|
|
|
|
}
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
2023-03-16 22:28:01 +00:00
|
|
|
|
|
|
|
// If szPathName is not the first item in strFiles, insert it at the top of the list
|
|
|
|
if (strFiles[0].CompareNoCase(szPathName) != 0)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
2023-03-16 22:28:01 +00:00
|
|
|
for (INT i = MAX_RECENT_FILES - 1; i > 0; --i)
|
|
|
|
strFiles[i] = strFiles[i - 1];
|
|
|
|
|
|
|
|
strFiles[0] = szPathName;
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
2015-08-16 19:52:37 +00:00
|
|
|
}
|