ReactOS 0.4.15-dev-8422-g6219a1a
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 // Build the local path to the converted cached BMP wallpaper
42 HRESULT hr;
43 WCHAR szWallpaper[MAX_PATH];
45 if (FAILED(hr))
46 return;
47 hr = StringCchCatW(szWallpaper, _countof(szWallpaper), TEXT("\\Wallpaper1.bmp"));
48 if (FAILED(hr))
49 return;
50
51 // Save the converted wallpaper BMP
53 HBITMAP hbmLocked = imageModel.LockBitmap();
54 img.Attach(hbmLocked);
55 hr = img.SaveDx(szWallpaper);
56 img.Detach();
57 imageModel.UnlockBitmap(hbmLocked);
58 if (FAILED(hr))
59 return;
60
61 // Write the wallpaper settings to the registry
62 CRegKey desktop;
63 if (desktop.Open(HKEY_CURRENT_USER, L"Control Panel\\Desktop") == ERROR_SUCCESS)
64 {
65 desktop.SetStringValue(L"Wallpaper", szFileName);
66 desktop.SetStringValue(L"WallpaperStyle", (style == RegistrySettings::STRETCHED) ? L"2" : L"0");
67 desktop.SetStringValue(L"TileWallpaper", (style == RegistrySettings::TILED) ? L"1" : L"0");
68 desktop.SetStringValue(L"ConvertedWallpaper", szWallpaper);
69 desktop.SetStringValue(L"OriginalWallpaper", szFileName);
70 }
71
72 // Set the desktop wallpaper
74}
75
77{
80 GridExtent = 1;
81 NoStretching = 0;
82 ShowThumbnail = 0;
83 SnapToGrid = 0;
84 ThumbHeight = 100;
85 ThumbWidth = 120;
86 ThumbXPos = 180;
87 ThumbYPos = 200;
88 UnitSetting = 0;
89 Bold = FALSE;
90 Italic = FALSE;
93 PointSize = 14;
102
103 LOGFONTW lf;
106
109 rc.left = rc.top = CW_USEDEFAULT;
110 rc.right = rc.left + 544;
111 rc.bottom = rc.top + 375;
112 WindowPlacement.showCmd = nCmdShow;
113}
114
116{
117 LoadPresets(nCmdShow);
118
119 CRegKey paint;
120 if (paint.Open(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint", KEY_READ) != ERROR_SUCCESS)
121 return;
122
124 if (view.Open(paint, L"View", KEY_READ) == ERROR_SUCCESS)
125 {
126 ReadDWORD(view, L"BMPHeight", BMPHeight);
127 ReadDWORD(view, L"BMPWidth", BMPWidth);
128 ReadDWORD(view, L"GridExtent", GridExtent);
129 ReadDWORD(view, L"NoStretching", NoStretching);
130 ReadDWORD(view, L"ShowThumbnail", ShowThumbnail);
131 ReadDWORD(view, L"SnapToGrid", SnapToGrid);
132 ReadDWORD(view, L"ThumbHeight", ThumbHeight);
133 ReadDWORD(view, L"ThumbWidth", ThumbWidth);
134 ReadDWORD(view, L"ThumbXPos", ThumbXPos);
135 ReadDWORD(view, L"ThumbYPos", ThumbYPos);
136 ReadDWORD(view, L"UnitSetting", UnitSetting);
137 ReadDWORD(view, L"ShowStatusBar", ShowStatusBar);
138
139 ULONG pnBytes = sizeof(WINDOWPLACEMENT);
140 view.QueryBinaryValue(L"WindowPlacement", &WindowPlacement, &pnBytes);
141 }
142
143 CRegKey files;
144 if (files.Open(paint, L"Recent File List", KEY_READ) == ERROR_SUCCESS)
145 {
146 WCHAR szName[64];
147 for (INT i = 0; i < MAX_RECENT_FILES; ++i)
148 {
149 StringCchPrintfW(szName, _countof(szName), L"File%u", i + 1);
150 ReadString(files, szName, strFiles[i]);
151 }
152 }
153
155 if (text.Open(paint, L"Text", KEY_READ) == ERROR_SUCCESS)
156 {
157 ReadDWORD(text, L"Bold", Bold);
158 ReadDWORD(text, L"Italic", Italic);
159 ReadDWORD(text, L"Underline", Underline);
160 ReadDWORD(text, L"CharSet", CharSet);
161 ReadDWORD(text, L"PointSize", PointSize);
162 ReadDWORD(text, L"PositionX", FontsPositionX);
163 ReadDWORD(text, L"PositionY", FontsPositionY);
164 ReadDWORD(text, L"ShowTextTool", ShowTextTool);
165 ReadString(text, L"TypeFaceName", strFontName, strFontName);
166 }
167
169 if (bar1.Open(paint, L"General-Bar1", KEY_READ) == ERROR_SUCCESS)
170 {
171 ReadDWORD(bar1, L"BarID", Bar1ID);
172 }
173
175 if (bar2.Open(paint, L"General-Bar2", KEY_READ) == ERROR_SUCCESS)
176 {
177 ReadDWORD(bar2, L"BarID", Bar2ID);
178 }
179
180 CRegKey bar3;
181 if (bar3.Open(paint, L"General-Bar3", KEY_READ) == ERROR_SUCCESS)
182 {
183 ReadDWORD(bar3, L"Visible", ShowToolBox);
184 }
185
186 CRegKey bar4;
187 if (bar4.Open(paint, L"General-Bar4", KEY_READ) == ERROR_SUCCESS)
188 {
189 ReadDWORD(bar4, L"Visible", ShowPalette);
190 }
191
192 // Fix the bitmap size if too large
193 if (BMPWidth > 5000)
195 if (BMPHeight > 5000)
197}
198
200{
203
204 CRegKey paint;
205 if (paint.Create(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint") != ERROR_SUCCESS)
206 return;
207
209 if (view.Create(paint, L"View") == ERROR_SUCCESS)
210 {
211 view.SetDWORDValue(L"BMPHeight", BMPHeight);
212 view.SetDWORDValue(L"BMPWidth", BMPWidth);
213 view.SetDWORDValue(L"GridExtent", GridExtent);
214 view.SetDWORDValue(L"NoStretching", NoStretching);
215 view.SetDWORDValue(L"ShowThumbnail", ShowThumbnail);
216 view.SetDWORDValue(L"SnapToGrid", SnapToGrid);
217 view.SetDWORDValue(L"ThumbHeight", ThumbHeight);
218 view.SetDWORDValue(L"ThumbWidth", ThumbWidth);
219 view.SetDWORDValue(L"ThumbXPos", ThumbXPos);
220 view.SetDWORDValue(L"ThumbYPos", ThumbYPos);
221 view.SetDWORDValue(L"UnitSetting", UnitSetting);
222 view.SetDWORDValue(L"ShowStatusBar", ShowStatusBar);
223
224 view.SetBinaryValue(L"WindowPlacement", &WindowPlacement, sizeof(WINDOWPLACEMENT));
225 }
226
227 CRegKey files;
228 if (files.Create(paint, L"Recent File List") == ERROR_SUCCESS)
229 {
230 WCHAR szName[64];
231 for (INT iFile = 0; iFile < MAX_RECENT_FILES; ++iFile)
232 {
233 StringCchPrintfW(szName, _countof(szName), L"File%u", iFile + 1);
235 }
236 }
237
239 if (text.Create(paint, L"Text") == ERROR_SUCCESS)
240 {
241 text.SetDWORDValue(L"Bold", Bold);
242 text.SetDWORDValue(L"Italic", Italic);
243 text.SetDWORDValue(L"Underline", Underline);
244 text.SetDWORDValue(L"CharSet", CharSet);
245 text.SetDWORDValue(L"PointSize", PointSize);
246 text.SetDWORDValue(L"PositionX", FontsPositionX);
247 text.SetDWORDValue(L"PositionY", FontsPositionY);
248 text.SetDWORDValue(L"ShowTextTool", ShowTextTool);
249 text.SetStringValue(L"TypeFaceName", strFontName);
250 }
251
253 if (bar1.Create(paint, L"General-Bar1") == ERROR_SUCCESS)
254 {
255 bar1.SetDWORDValue(L"BarID", Bar1ID);
256 }
257
259 if (bar2.Create(paint, L"General-Bar2") == ERROR_SUCCESS)
260 {
261 bar2.SetDWORDValue(L"BarID", Bar2ID);
262 }
263
264 CRegKey bar3;
265 if (bar3.Create(paint, L"General-Bar3") == ERROR_SUCCESS)
266 {
267 bar3.SetDWORDValue(L"Visible", ShowToolBox);
268 }
269
270 CRegKey bar4;
271 if (bar4.Create(paint, L"General-Bar4") == ERROR_SUCCESS)
272 {
273 bar4.SetDWORDValue(L"Visible", ShowPalette);
274 }
275}
276
278{
279 // Register the file to the user's 'Recent' folder
280 if (szPathName && szPathName[0])
281 SHAddToRecentDocs(SHARD_PATHW, szPathName);
282
283 // If szPathName is present in strFiles, move it to the top of the list
284 for (INT i = MAX_RECENT_FILES - 1, iFound = -1; i > 0; --i)
285 {
286 if (iFound < 0 && strFiles[i].CompareNoCase(szPathName) == 0)
287 iFound = i;
288
289 if (iFound >= 0)
290 Swap(strFiles[i], strFiles[i - 1]);
291 }
292
293 // If szPathName is not the first item in strFiles, insert it at the top of the list
294 if (strFiles[0].CompareNoCase(szPathName) != 0)
295 {
296 for (INT i = MAX_RECENT_FILES - 1; i > 0; --i)
297 strFiles[i] = strFiles[i - 1];
298
299 strFiles[0] = szPathName;
300 }
301}
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:387
int GetWidth() const
Definition: history.cpp:253
HBITMAP LockBitmap()
Definition: history.cpp:345
void UnlockBitmap(HBITMAP hbmLocked)
Definition: history.cpp:354
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:277
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:76
DWORD SnapToGrid
Definition: registry.h:23
WINDOWPLACEMENT WindowPlacement
Definition: registry.h:29
void Load(INT nCmdShow)
Definition: registry.cpp:115
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 NULL
Definition: types.h:112
#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
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2589
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Swap(a, b)
Definition: geom.c:201
GLint GLvoid * img
Definition: gl.h:1956
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 FAILED(hr)
Definition: intsafe.h:51
#define TEXT(s)
Definition: k32.h:26
#define error(str)
Definition: mkdosfs.c:1605
static HBITMAP
Definition: button.c:44
#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
#define CSIDL_FLAG_CREATE
void WINAPI SHAddToRecentDocs(UINT uFlags, LPCVOID pv)
Definition: shellord.c:1005
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_LOCAL_APPDATA
Definition: shlobj.h:2199
#define SHARD_PATHW
Definition: shlobj.h:1176
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
RECT rcNormalPosition
Definition: winuser.h:3295
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:960
#define SPI_SETDESKWALLPAPER
Definition: winuser.h:1369
#define SPIF_SENDCHANGE
Definition: winuser.h:1572
#define SPIF_UPDATEINIFILE
Definition: winuser.h:1571
BOOL WINAPI SystemParametersInfoW(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)
#define CW_USEDEFAULT
Definition: winuser.h:225
#define SM_CXSCREEN
Definition: winuser.h:959
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