ReactOS 0.4.15-dev-7693-gd0e2924
registry.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4 * PURPOSE: Offering functions dealing with registry values
5 * COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
6 * Copyright 2020 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7 */
8
9#include "precomp.h"
10#include <winreg.h>
11#include <wincon.h>
12#include <shlobj.h>
13
15
16/* FUNCTIONS ********************************************************/
17
18static void ReadDWORD(CRegKey &key, LPCWSTR lpName, DWORD &dwValue)
19{
20 DWORD dwTemp;
21 if (key.QueryDWORDValue(lpName, dwTemp) == ERROR_SUCCESS)
22 dwValue = dwTemp;
23}
24
25static void ReadString(CRegKey &key, LPCWSTR lpName, CStringW &strValue, LPCWSTR lpDefault = L"")
26{
27 CStringW strTemp;
28 ULONG nChars = MAX_PATH;
29 LPWSTR psz = strTemp.GetBuffer(nChars);
30 LONG error = key.QueryStringValue(lpName, psz, &nChars);
31 strTemp.ReleaseBuffer();
32
33 if (error == ERROR_SUCCESS)
34 strValue = strTemp;
35 else
36 strValue = lpDefault;
37}
38
40{
41 CRegKey desktop;
42 if (desktop.Open(HKEY_CURRENT_USER, L"Control Panel\\Desktop") == ERROR_SUCCESS)
43 {
44 desktop.SetStringValue(L"Wallpaper", szFileName);
45
46 desktop.SetStringValue(L"WallpaperStyle", (style == RegistrySettings::STRETCHED) ? L"2" : L"0");
47 desktop.SetStringValue(L"TileWallpaper", (style == RegistrySettings::TILED) ? L"1" : L"0");
48 }
49
51}
52
54{
57 GridExtent = 1;
58 NoStretching = 0;
59 ShowThumbnail = 0;
60 SnapToGrid = 0;
61 ThumbHeight = 100;
62 ThumbWidth = 120;
63 ThumbXPos = 180;
64 ThumbYPos = 200;
65 UnitSetting = 0;
66 Bold = FALSE;
67 Italic = FALSE;
70 PointSize = 14;
79
80 LOGFONTW lf;
83
86 rc.left = rc.top = CW_USEDEFAULT;
87 rc.right = rc.left + 544;
88 rc.bottom = rc.top + 375;
89 WindowPlacement.showCmd = nCmdShow;
90}
91
93{
94 LoadPresets(nCmdShow);
95
96 CRegKey paint;
97 if (paint.Open(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint", KEY_READ) != ERROR_SUCCESS)
98 return;
99
101 if (view.Open(paint, L"View", KEY_READ) == ERROR_SUCCESS)
102 {
103 ReadDWORD(view, L"BMPHeight", BMPHeight);
104 ReadDWORD(view, L"BMPWidth", BMPWidth);
105 ReadDWORD(view, L"GridExtent", GridExtent);
106 ReadDWORD(view, L"NoStretching", NoStretching);
107 ReadDWORD(view, L"ShowThumbnail", ShowThumbnail);
108 ReadDWORD(view, L"SnapToGrid", SnapToGrid);
109 ReadDWORD(view, L"ThumbHeight", ThumbHeight);
110 ReadDWORD(view, L"ThumbWidth", ThumbWidth);
111 ReadDWORD(view, L"ThumbXPos", ThumbXPos);
112 ReadDWORD(view, L"ThumbYPos", ThumbYPos);
113 ReadDWORD(view, L"UnitSetting", UnitSetting);
114 ReadDWORD(view, L"ShowStatusBar", ShowStatusBar);
115
116 ULONG pnBytes = sizeof(WINDOWPLACEMENT);
117 view.QueryBinaryValue(L"WindowPlacement", &WindowPlacement, &pnBytes);
118 }
119
120 CRegKey files;
121 if (files.Open(paint, L"Recent File List", KEY_READ) == ERROR_SUCCESS)
122 {
123 WCHAR szName[64];
124 for (INT i = 0; i < MAX_RECENT_FILES; ++i)
125 {
126 StringCchPrintfW(szName, _countof(szName), L"File%u", i + 1);
127 ReadString(files, szName, strFiles[i]);
128 }
129 }
130
132 if (text.Open(paint, L"Text", KEY_READ) == ERROR_SUCCESS)
133 {
134 ReadDWORD(text, L"Bold", Bold);
135 ReadDWORD(text, L"Italic", Italic);
136 ReadDWORD(text, L"Underline", Underline);
137 ReadDWORD(text, L"CharSet", CharSet);
138 ReadDWORD(text, L"PointSize", PointSize);
139 ReadDWORD(text, L"PositionX", FontsPositionX);
140 ReadDWORD(text, L"PositionY", FontsPositionY);
141 ReadDWORD(text, L"ShowTextTool", ShowTextTool);
142 ReadString(text, L"TypeFaceName", strFontName, strFontName);
143 }
144
146 if (bar1.Open(paint, L"General-Bar1", KEY_READ) == ERROR_SUCCESS)
147 {
148 ReadDWORD(bar1, L"BarID", Bar1ID);
149 }
150
152 if (bar2.Open(paint, L"General-Bar2", KEY_READ) == ERROR_SUCCESS)
153 {
154 ReadDWORD(bar2, L"BarID", Bar2ID);
155 }
156
157 CRegKey bar3;
158 if (bar3.Open(paint, L"General-Bar3", KEY_READ) == ERROR_SUCCESS)
159 {
160 ReadDWORD(bar3, L"Visible", ShowToolBox);
161 }
162
163 CRegKey bar4;
164 if (bar4.Open(paint, L"General-Bar4", KEY_READ) == ERROR_SUCCESS)
165 {
166 ReadDWORD(bar4, L"Visible", ShowPalette);
167 }
168
169 // Fix the bitmap size if too large
170 if (BMPWidth > 5000)
172 if (BMPHeight > 5000)
174}
175
177{
180
181 CRegKey paint;
182 if (paint.Create(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint") != ERROR_SUCCESS)
183 return;
184
186 if (view.Create(paint, L"View") == ERROR_SUCCESS)
187 {
188 view.SetDWORDValue(L"BMPHeight", BMPHeight);
189 view.SetDWORDValue(L"BMPWidth", BMPWidth);
190 view.SetDWORDValue(L"GridExtent", GridExtent);
191 view.SetDWORDValue(L"NoStretching", NoStretching);
192 view.SetDWORDValue(L"ShowThumbnail", ShowThumbnail);
193 view.SetDWORDValue(L"SnapToGrid", SnapToGrid);
194 view.SetDWORDValue(L"ThumbHeight", ThumbHeight);
195 view.SetDWORDValue(L"ThumbWidth", ThumbWidth);
196 view.SetDWORDValue(L"ThumbXPos", ThumbXPos);
197 view.SetDWORDValue(L"ThumbYPos", ThumbYPos);
198 view.SetDWORDValue(L"UnitSetting", UnitSetting);
199 view.SetDWORDValue(L"ShowStatusBar", ShowStatusBar);
200
201 view.SetBinaryValue(L"WindowPlacement", &WindowPlacement, sizeof(WINDOWPLACEMENT));
202 }
203
204 CRegKey files;
205 if (files.Create(paint, L"Recent File List") == ERROR_SUCCESS)
206 {
207 WCHAR szName[64];
208 for (INT iFile = 0; iFile < MAX_RECENT_FILES; ++iFile)
209 {
210 StringCchPrintfW(szName, _countof(szName), L"File%u", iFile + 1);
212 }
213 }
214
216 if (text.Create(paint, L"Text") == ERROR_SUCCESS)
217 {
218 text.SetDWORDValue(L"Bold", Bold);
219 text.SetDWORDValue(L"Italic", Italic);
220 text.SetDWORDValue(L"Underline", Underline);
221 text.SetDWORDValue(L"CharSet", CharSet);
222 text.SetDWORDValue(L"PointSize", PointSize);
223 text.SetDWORDValue(L"PositionX", FontsPositionX);
224 text.SetDWORDValue(L"PositionY", FontsPositionY);
225 text.SetDWORDValue(L"ShowTextTool", ShowTextTool);
226 text.SetStringValue(L"TypeFaceName", strFontName);
227 }
228
230 if (bar1.Create(paint, L"General-Bar1") == ERROR_SUCCESS)
231 {
232 bar1.SetDWORDValue(L"BarID", Bar1ID);
233 }
234
236 if (bar2.Create(paint, L"General-Bar2") == ERROR_SUCCESS)
237 {
238 bar2.SetDWORDValue(L"BarID", Bar2ID);
239 }
240
241 CRegKey bar3;
242 if (bar3.Create(paint, L"General-Bar3") == ERROR_SUCCESS)
243 {
244 bar3.SetDWORDValue(L"Visible", ShowToolBox);
245 }
246
247 CRegKey bar4;
248 if (bar4.Create(paint, L"General-Bar4") == ERROR_SUCCESS)
249 {
250 bar4.SetDWORDValue(L"Visible", ShowPalette);
251 }
252}
253
255{
256 // Register the file to the user's 'Recent' folder
257 if (szPathName && szPathName[0])
258 SHAddToRecentDocs(SHARD_PATHW, szPathName);
259
260 // If szPathName is present in strFiles, move it to the top of the list
261 for (INT i = MAX_RECENT_FILES - 1, iFound = -1; i > 0; --i)
262 {
263 if (iFound < 0 && strFiles[i].CompareNoCase(szPathName) == 0)
264 iFound = i;
265
266 if (iFound >= 0)
267 Swap(strFiles[i], strFiles[i - 1]);
268 }
269
270 // If szPathName is not the first item in strFiles, insert it at the top of the list
271 if (strFiles[0].CompareNoCase(szPathName) != 0)
272 {
273 for (INT i = MAX_RECENT_FILES - 1; i > 0; --i)
274 strFiles[i] = strFiles[i - 1];
275
276 strFiles[0] = szPathName;
277 }
278}
Arabic default style
Definition: afstyles.h:94
static void ReadDWORD(CRegKey &key, LPCWSTR lpName, DWORD &dwValue)
Definition: registry.cpp:18
static void ReadString(CRegKey &key, LPCWSTR lpName, CStringW &strValue, LPCWSTR lpDefault=L"")
Definition: registry.cpp:25
RegistrySettings registrySettings
Definition: registry.cpp:14
#define BAR1ID_TOP
Definition: registry.h:50
#define BAR2ID_LEFT
Definition: registry.h:55
#define MAX_RECENT_FILES
Definition: registry.h:10
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE) noexcept
Definition: atlbase.h:1173
LONG SetStringValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwType=REG_SZ) noexcept
Definition: atlbase.h:1315
LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue) noexcept
Definition: atlbase.h:1310
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass=REG_NONE, DWORD dwOptions=REG_OPTION_NON_VOLATILE, REGSAM samDesired=KEY_READ|KEY_WRITE, LPSECURITY_ATTRIBUTES lpSecAttr=NULL, LPDWORD lpdwDisposition=NULL) noexcept
Definition: atlbase.h:1189
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:382
int GetWidth() const
Definition: history.cpp:253
int GetHeight() const
Definition: history.cpp:258
DWORD PointSize
Definition: registry.h:34
DWORD UnitSetting
Definition: registry.h:28
DWORD ShowTextTool
Definition: registry.h:41
DWORD ThumbXPos
Definition: registry.h:26
DWORD GridExtent
Definition: registry.h:20
DWORD ShowToolBox
Definition: registry.h:44
DWORD BMPWidth
Definition: registry.h:19
DWORD FontsPositionY
Definition: registry.h:40
DWORD ShowPalette
Definition: registry.h:43
DWORD ThumbYPos
Definition: registry.h:27
DWORD ThumbWidth
Definition: registry.h:25
DWORD FontsPositionX
Definition: registry.h:39
void SetMostRecentFile(LPCWSTR szPathName)
Definition: registry.cpp:254
DWORD ShowThumbnail
Definition: registry.h:22
DWORD Underline
Definition: registry.h:37
DWORD ShowStatusBar
Definition: registry.h:42
DWORD NoStretching
Definition: registry.h:21
CStringW strFiles[MAX_RECENT_FILES]
Definition: registry.h:31
void LoadPresets(INT nCmdShow)
Definition: registry.cpp:53
DWORD SnapToGrid
Definition: registry.h:23
WINDOWPLACEMENT WindowPlacement
Definition: registry.h:29
void Load(INT nCmdShow)
Definition: registry.cpp:92
DWORD BMPHeight
Definition: registry.h:18
DWORD ThumbHeight
Definition: registry.h:24
CStringW strFontName
Definition: registry.h:33
static void SetWallpaper(LPCWSTR szFileName, WallpaperStyle style)
Definition: registry.cpp:39
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
const WCHAR * text
Definition: package.c:1799
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Swap(a, b)
Definition: geom.c:201
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ImageModel imageModel
Definition: history.cpp:11
#define error(str)
Definition: mkdosfs.c:1605
#define KEY_READ
Definition: nt_native.h:1023
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
static const WCHAR szName[]
Definition: powrprof.c:45
void WINAPI SHAddToRecentDocs(UINT uFlags, LPCVOID pv)
Definition: shellord.c:810
#define SHARD_PATHW
Definition: shlobj.h:1169
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
RECT rcNormalPosition
Definition: winuser.h:3294
Definition: copy.c:22
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define ZeroMemory
Definition: winbase.h:1712
_In_ LPCSTR lpName
Definition: winbase.h:2789
_In_ ULONG_PTR iFile
Definition: winddi.h:3835
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
#define DEFAULT_GUI_FONT
Definition: wingdi.h:909
#define DEFAULT_CHARSET
Definition: wingdi.h:384
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define SM_CYSCREEN
Definition: winuser.h:959
#define SPI_SETDESKWALLPAPER
Definition: winuser.h:1368
#define SPIF_SENDCHANGE
Definition: winuser.h:1571
#define SPIF_UPDATEINIFILE
Definition: winuser.h:1570
#define CW_USEDEFAULT
Definition: winuser.h:225
#define SM_CXSCREEN
Definition: winuser.h:958
#define SystemParametersInfo
Definition: winuser.h:5857
struct _WINDOWPLACEMENT WINDOWPLACEMENT
int WINAPI GetSystemMetrics(_In_ int)
VOID bar2(IN PLONG BlackHole, IN PLONG BadAddress, IN PLONG Counter)
Definition: xcpt4u.c:3283
VOID bar1(IN NTSTATUS Status, IN PLONG Counter)
Definition: xcpt4u.c:3266
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185