2015-05-08 16:02:36 +00:00
|
|
|
/*
|
2023-06-23 11:04:32 +00:00
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
|
|
|
|
* PURPOSE: Offering functions dealing with registry values
|
2023-06-27 18:22:21 +00:00
|
|
|
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
|
2023-06-23 11:04:32 +00:00
|
|
|
* Copyright 2020 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
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-11-04 10:25:45 +00:00
|
|
|
static void ReadDWORD(CRegKey &key, LPCWSTR 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
|
|
|
|
2023-11-04 10:25:45 +00:00
|
|
|
static void ReadString(CRegKey &key, LPCWSTR lpName, CStringW &strValue, LPCWSTR lpDefault = L"")
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
CStringW strTemp;
|
2016-10-01 20:04:43 +00:00
|
|
|
ULONG nChars = MAX_PATH;
|
2023-11-04 10:25:45 +00:00
|
|
|
LPWSTR psz = strTemp.GetBuffer(nChars);
|
2022-01-05 07:26:05 +00:00
|
|
|
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
|
|
|
|
2023-11-04 10:25:45 +00:00
|
|
|
void RegistrySettings::SetWallpaper(LPCWSTR szFileName, RegistrySettings::WallpaperStyle style)
|
2016-10-01 20:04:43 +00:00
|
|
|
{
|
|
|
|
CRegKey desktop;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (desktop.Open(HKEY_CURRENT_USER, L"Control Panel\\Desktop") == ERROR_SUCCESS)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
desktop.SetStringValue(L"Wallpaper", szFileName);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2023-11-04 10:25:45 +00:00
|
|
|
desktop.SetStringValue(L"WallpaperStyle", (style == RegistrySettings::STRETCHED) ? L"2" : L"0");
|
|
|
|
desktop.SetStringValue(L"TileWallpaper", (style == RegistrySettings::TILED) ? L"1" : L"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
|
|
|
|
2023-11-04 10:25:45 +00:00
|
|
|
LOGFONTW lf;
|
|
|
|
::GetObjectW(GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf);
|
2022-01-05 07:26:05 +00:00
|
|
|
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;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (paint.Open(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint", KEY_READ) != ERROR_SUCCESS)
|
2023-03-18 08:12:28 +00:00
|
|
|
return;
|
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
CRegKey view;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (view.Open(paint, L"View", KEY_READ) == ERROR_SUCCESS)
|
2015-08-16 19:52:37 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
ReadDWORD(view, L"BMPHeight", BMPHeight);
|
|
|
|
ReadDWORD(view, L"BMPWidth", BMPWidth);
|
|
|
|
ReadDWORD(view, L"GridExtent", GridExtent);
|
|
|
|
ReadDWORD(view, L"NoStretching", NoStretching);
|
|
|
|
ReadDWORD(view, L"ShowThumbnail", ShowThumbnail);
|
|
|
|
ReadDWORD(view, L"SnapToGrid", SnapToGrid);
|
|
|
|
ReadDWORD(view, L"ThumbHeight", ThumbHeight);
|
|
|
|
ReadDWORD(view, L"ThumbWidth", ThumbWidth);
|
|
|
|
ReadDWORD(view, L"ThumbXPos", ThumbXPos);
|
|
|
|
ReadDWORD(view, L"ThumbYPos", ThumbYPos);
|
|
|
|
ReadDWORD(view, L"UnitSetting", UnitSetting);
|
|
|
|
ReadDWORD(view, L"ShowStatusBar", ShowStatusBar);
|
2016-10-01 20:04:43 +00:00
|
|
|
|
|
|
|
ULONG pnBytes = sizeof(WINDOWPLACEMENT);
|
2023-11-04 10:25:45 +00:00
|
|
|
view.QueryBinaryValue(L"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-11-04 10:25:45 +00:00
|
|
|
if (files.Open(paint, L"Recent File List", KEY_READ) == ERROR_SUCCESS)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
WCHAR szName[64];
|
2023-03-16 22:28:01 +00:00
|
|
|
for (INT i = 0; i < MAX_RECENT_FILES; ++i)
|
|
|
|
{
|
2023-11-03 20:56:10 +00:00
|
|
|
StringCchPrintfW(szName, _countof(szName), L"File%u", i + 1);
|
2023-03-16 22:28:01 +00:00
|
|
|
ReadString(files, szName, strFiles[i]);
|
|
|
|
}
|
2022-01-05 07:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CRegKey text;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (text.Open(paint, L"Text", KEY_READ) == ERROR_SUCCESS)
|
2022-01-05 07:26:05 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
ReadDWORD(text, L"Bold", Bold);
|
|
|
|
ReadDWORD(text, L"Italic", Italic);
|
|
|
|
ReadDWORD(text, L"Underline", Underline);
|
|
|
|
ReadDWORD(text, L"CharSet", CharSet);
|
|
|
|
ReadDWORD(text, L"PointSize", PointSize);
|
|
|
|
ReadDWORD(text, L"PositionX", FontsPositionX);
|
|
|
|
ReadDWORD(text, L"PositionY", FontsPositionY);
|
|
|
|
ReadDWORD(text, L"ShowTextTool", ShowTextTool);
|
|
|
|
ReadString(text, L"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;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (bar1.Open(paint, L"General-Bar1", KEY_READ) == ERROR_SUCCESS)
|
2023-04-04 10:06:06 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
ReadDWORD(bar1, L"BarID", Bar1ID);
|
2023-04-04 10:06:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 05:34:56 +00:00
|
|
|
CRegKey bar2;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (bar2.Open(paint, L"General-Bar2", KEY_READ) == ERROR_SUCCESS)
|
2023-04-03 05:34:56 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
ReadDWORD(bar2, L"BarID", Bar2ID);
|
2023-04-03 05:34:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-18 08:19:56 +00:00
|
|
|
CRegKey bar3;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (bar3.Open(paint, L"General-Bar3", KEY_READ) == ERROR_SUCCESS)
|
2023-03-18 08:19:56 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
ReadDWORD(bar3, L"Visible", ShowToolBox);
|
2023-03-18 08:19:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-18 08:12:28 +00:00
|
|
|
CRegKey bar4;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (bar4.Open(paint, L"General-Bar4", KEY_READ) == ERROR_SUCCESS)
|
2023-03-18 08:12:28 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
ReadDWORD(bar4, L"Visible", ShowPalette);
|
2023-03-18 08:12:28 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (paint.Create(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint") != ERROR_SUCCESS)
|
2023-03-18 08:12:28 +00:00
|
|
|
return;
|
|
|
|
|
2016-10-01 20:04:43 +00:00
|
|
|
CRegKey view;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (view.Create(paint, L"View") == ERROR_SUCCESS)
|
2015-08-16 19:52:37 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
view.SetDWORDValue(L"BMPHeight", BMPHeight);
|
|
|
|
view.SetDWORDValue(L"BMPWidth", BMPWidth);
|
|
|
|
view.SetDWORDValue(L"GridExtent", GridExtent);
|
|
|
|
view.SetDWORDValue(L"NoStretching", NoStretching);
|
|
|
|
view.SetDWORDValue(L"ShowThumbnail", ShowThumbnail);
|
|
|
|
view.SetDWORDValue(L"SnapToGrid", SnapToGrid);
|
|
|
|
view.SetDWORDValue(L"ThumbHeight", ThumbHeight);
|
|
|
|
view.SetDWORDValue(L"ThumbWidth", ThumbWidth);
|
|
|
|
view.SetDWORDValue(L"ThumbXPos", ThumbXPos);
|
|
|
|
view.SetDWORDValue(L"ThumbYPos", ThumbYPos);
|
|
|
|
view.SetDWORDValue(L"UnitSetting", UnitSetting);
|
|
|
|
view.SetDWORDValue(L"ShowStatusBar", ShowStatusBar);
|
|
|
|
|
|
|
|
view.SetBinaryValue(L"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-11-04 10:25:45 +00:00
|
|
|
if (files.Create(paint, L"Recent File List") == ERROR_SUCCESS)
|
2016-09-26 19:53:42 +00:00
|
|
|
{
|
2023-11-03 20:56:10 +00:00
|
|
|
WCHAR szName[64];
|
2023-03-16 22:28:01 +00:00
|
|
|
for (INT iFile = 0; iFile < MAX_RECENT_FILES; ++iFile)
|
|
|
|
{
|
2023-11-03 20:56:10 +00:00
|
|
|
StringCchPrintfW(szName, _countof(szName), L"File%u", iFile + 1);
|
2023-03-16 22:28:01 +00:00
|
|
|
files.SetStringValue(szName, strFiles[iFile]);
|
|
|
|
}
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
2022-01-05 07:26:05 +00:00
|
|
|
|
|
|
|
CRegKey text;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (text.Create(paint, L"Text") == ERROR_SUCCESS)
|
2022-01-05 07:26:05 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
text.SetDWORDValue(L"Bold", Bold);
|
|
|
|
text.SetDWORDValue(L"Italic", Italic);
|
|
|
|
text.SetDWORDValue(L"Underline", Underline);
|
|
|
|
text.SetDWORDValue(L"CharSet", CharSet);
|
|
|
|
text.SetDWORDValue(L"PointSize", PointSize);
|
|
|
|
text.SetDWORDValue(L"PositionX", FontsPositionX);
|
|
|
|
text.SetDWORDValue(L"PositionY", FontsPositionY);
|
|
|
|
text.SetDWORDValue(L"ShowTextTool", ShowTextTool);
|
|
|
|
text.SetStringValue(L"TypeFaceName", strFontName);
|
2022-01-05 07:26:05 +00:00
|
|
|
}
|
2023-03-18 08:12:28 +00:00
|
|
|
|
2023-04-04 10:06:06 +00:00
|
|
|
CRegKey bar1;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (bar1.Create(paint, L"General-Bar1") == ERROR_SUCCESS)
|
2023-04-04 10:06:06 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
bar1.SetDWORDValue(L"BarID", Bar1ID);
|
2023-04-04 10:06:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 05:34:56 +00:00
|
|
|
CRegKey bar2;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (bar2.Create(paint, L"General-Bar2") == ERROR_SUCCESS)
|
2023-04-03 05:34:56 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
bar2.SetDWORDValue(L"BarID", Bar2ID);
|
2023-04-03 05:34:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-18 08:19:56 +00:00
|
|
|
CRegKey bar3;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (bar3.Create(paint, L"General-Bar3") == ERROR_SUCCESS)
|
2023-03-18 08:19:56 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
bar3.SetDWORDValue(L"Visible", ShowToolBox);
|
2023-03-18 08:19:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-18 08:12:28 +00:00
|
|
|
CRegKey bar4;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (bar4.Create(paint, L"General-Bar4") == ERROR_SUCCESS)
|
2023-03-18 08:12:28 +00:00
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
bar4.SetDWORDValue(L"Visible", ShowPalette);
|
2023-03-18 08:12:28 +00:00
|
|
|
}
|
2016-09-26 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
2023-11-04 10:25:45 +00:00
|
|
|
void RegistrySettings::SetMostRecentFile(LPCWSTR 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)
|
2023-11-18 02:23:13 +00:00
|
|
|
Swap(strFiles[i], strFiles[i - 1]);
|
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
|
|
|
}
|