ReactOS  0.4.15-dev-5459-gb85f005
registry.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: PAINT for ReactOS
3  * LICENSE: LGPL
4  * FILE: base/applications/mspaint/registry.cpp
5  * PURPOSE: Offering functions dealing with registry values
6  * PROGRAMMERS: Benedikt Freisen
7  * Katayama Hirofumi MZ
8  */
9 
10 /* INCLUDES *********************************************************/
11 
12 #include "precomp.h"
13 #include <winreg.h>
14 #include <wincon.h>
15 #include <shlobj.h>
16 
17 /* FUNCTIONS ********************************************************/
18 static DWORD ReadDWORD(CRegKey &key, LPCTSTR lpName, DWORD &dwValue, BOOL bCheckForDef)
19 {
20  DWORD dwPrev = dwValue;
21 
22  if (key.QueryDWORDValue(lpName, dwValue) != ERROR_SUCCESS || (bCheckForDef && dwValue == 0))
23  dwValue = dwPrev;
24 
25  return dwPrev;
26 }
27 
28 static void ReadString(CRegKey &key, LPCTSTR lpName, CString &strValue, LPCTSTR lpDefault = TEXT(""))
29 {
30  CString strTemp;
31  ULONG nChars = MAX_PATH;
32  LPTSTR psz = strTemp.GetBuffer(nChars);
33  LONG error = key.QueryStringValue(lpName, psz, &nChars);
34  strTemp.ReleaseBuffer();
35 
36  if (error == ERROR_SUCCESS)
37  strValue = strTemp;
38  else
39  strValue = lpDefault;
40 }
41 
43 {
44  CRegKey desktop;
45  if (desktop.Open(HKEY_CURRENT_USER, _T("Control Panel\\Desktop")) == ERROR_SUCCESS)
46  {
47  desktop.SetStringValue(_T("Wallpaper"), szFileName);
48 
49  desktop.SetStringValue(_T("WallpaperStyle"), (style == RegistrySettings::STRETCHED) ? _T("2") : _T("0"));
50  desktop.SetStringValue(_T("TileWallpaper"), (style == RegistrySettings::TILED) ? _T("1") : _T("0"));
51  }
52 
54 }
55 
57 {
60  GridExtent = 1;
61  NoStretching = 0;
62  ShowThumbnail = 0;
63  SnapToGrid = 0;
64  ThumbHeight = 100;
65  ThumbWidth = 120;
66  ThumbXPos = 180;
67  ThumbYPos = 200;
68  UnitSetting = 0;
69  Bold = FALSE;
70  Italic = FALSE;
71  Underline = FALSE;
73  PointSize = 14;
74  FontsPositionX = 0;
75  FontsPositionY = 0;
77 
78  LOGFONT lf;
79  GetObject(GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf);
81 
83 }
84 
86 {
87  LoadPresets();
88 
89  CRegKey view;
90  if (view.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), KEY_READ) == ERROR_SUCCESS)
91  {
92  ReadDWORD(view, _T("BMPHeight"), BMPHeight, TRUE);
93  ReadDWORD(view, _T("BMPWidth"), BMPWidth, TRUE);
94  ReadDWORD(view, _T("GridExtent"), GridExtent, FALSE);
95  ReadDWORD(view, _T("NoStretching"), NoStretching, FALSE);
96  ReadDWORD(view, _T("ShowThumbnail"), ShowThumbnail, FALSE);
97  ReadDWORD(view, _T("SnapToGrid"), SnapToGrid, FALSE);
98  ReadDWORD(view, _T("ThumbHeight"), ThumbHeight, TRUE);
99  ReadDWORD(view, _T("ThumbWidth"), ThumbWidth, TRUE);
100  ReadDWORD(view, _T("ThumbXPos"), ThumbXPos, TRUE);
101  ReadDWORD(view, _T("ThumbYPos"), ThumbYPos, TRUE);
102  ReadDWORD(view, _T("UnitSetting"), UnitSetting, FALSE);
103 
104  ULONG pnBytes = sizeof(WINDOWPLACEMENT);
105  view.QueryBinaryValue(_T("WindowPlacement"), &WindowPlacement, &pnBytes);
106  }
107 
108  CRegKey files;
109  if (files.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), KEY_READ) == ERROR_SUCCESS)
110  {
111  ReadString(files, _T("File1"), strFile1);
112  ReadString(files, _T("File2"), strFile2);
113  ReadString(files, _T("File3"), strFile3);
114  ReadString(files, _T("File4"), strFile4);
115  }
116 
117  CRegKey text;
118  if (text.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Text"), KEY_READ) == ERROR_SUCCESS)
119  {
120  ReadDWORD(text, _T("Bold"), Bold, FALSE);
121  ReadDWORD(text, _T("Italic"), Italic, FALSE);
122  ReadDWORD(text, _T("Underline"), Underline, FALSE);
123  ReadDWORD(text, _T("CharSet"), CharSet, FALSE);
124  ReadDWORD(text, _T("PointSize"), PointSize, FALSE);
125  ReadDWORD(text, _T("PositionX"), FontsPositionX, FALSE);
126  ReadDWORD(text, _T("PositionY"), FontsPositionY, FALSE);
127  ReadDWORD(text, _T("ShowTextTool"), ShowTextTool, FALSE);
128  ReadString(text, _T("TypeFaceName"), strFontName, strFontName);
129  }
130 
131  // Fix the bitmap size if too large
132  if (BMPWidth > 5000)
133  BMPWidth = (GetSystemMetrics(SM_CXSCREEN) * 6) / 10;
134  if (BMPHeight > 5000)
135  BMPHeight = (GetSystemMetrics(SM_CYSCREEN) * 6) / 10;
136 }
137 
139 {
140  CRegKey view;
141  if (view.Create(HKEY_CURRENT_USER,
142  _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View")) == ERROR_SUCCESS)
143  {
144  view.SetDWORDValue(_T("BMPHeight"), BMPHeight);
145  view.SetDWORDValue(_T("BMPWidth"), BMPWidth);
146  view.SetDWORDValue(_T("GridExtent"), GridExtent);
147  view.SetDWORDValue(_T("NoStretching"), NoStretching);
148  view.SetDWORDValue(_T("ShowThumbnail"), ShowThumbnail);
149  view.SetDWORDValue(_T("SnapToGrid"), SnapToGrid);
150  view.SetDWORDValue(_T("ThumbHeight"), ThumbHeight);
151  view.SetDWORDValue(_T("ThumbWidth"), ThumbWidth);
152  view.SetDWORDValue(_T("ThumbXPos"), ThumbXPos);
153  view.SetDWORDValue(_T("ThumbYPos"), ThumbYPos);
154  view.SetDWORDValue(_T("UnitSetting"), UnitSetting);
155 
156  view.SetBinaryValue(_T("WindowPlacement"), &WindowPlacement, sizeof(WINDOWPLACEMENT));
157  }
158 
159  CRegKey files;
160  if (files.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List")) == ERROR_SUCCESS)
161  {
162  if (!strFile1.IsEmpty())
163  files.SetStringValue(_T("File1"), strFile1);
164  if (!strFile2.IsEmpty())
165  files.SetStringValue(_T("File2"), strFile2);
166  if (!strFile3.IsEmpty())
167  files.SetStringValue(_T("File3"), strFile3);
168  if (!strFile4.IsEmpty())
169  files.SetStringValue(_T("File4"), strFile4);
170  }
171 
172  CRegKey text;
173  if (text.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Text")) == ERROR_SUCCESS)
174  {
175  text.SetDWORDValue(_T("Bold"), Bold);
176  text.SetDWORDValue(_T("Italic"), Italic);
177  text.SetDWORDValue(_T("Underline"), Underline);
178  text.SetDWORDValue(_T("CharSet"), CharSet);
179  text.SetDWORDValue(_T("PointSize"), PointSize);
180  text.SetDWORDValue(_T("PositionX"), FontsPositionX);
181  text.SetDWORDValue(_T("PositionY"), FontsPositionY);
182  text.SetDWORDValue(_T("ShowTextTool"), ShowTextTool);
183  text.SetStringValue(_T("TypeFaceName"), strFontName);
184  }
185 }
186 
188 {
189  if (szPathName && szPathName[0])
190  SHAddToRecentDocs(SHARD_PATHW, szPathName);
191 
192  if (strFile1 == szPathName)
193  {
194  // do nothing
195  }
196  else if (strFile2 == szPathName)
197  {
198  CString strTemp = strFile2;
199  strFile2 = strFile1;
200  strFile1 = strTemp;
201  }
202  else if (strFile3 == szPathName)
203  {
204  CString strTemp = strFile3;
205  strFile3 = strFile2;
206  strFile2 = strFile1;
207  strFile1 = strTemp;
208  }
209  else if (strFile4 == szPathName)
210  {
211  CString strTemp = strFile4;
212  strFile4 = strFile3;
213  strFile3 = strFile2;
214  strFile2 = strFile1;
215  strFile1 = strTemp;
216  }
217  else
218  {
219  strFile4 = strFile3;
220  strFile3 = strFile2;
221  strFile2 = strFile1;
222  strFile1 = szPathName;
223  }
224 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
DWORD ThumbXPos
Definition: registry.h:25
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
struct _WINDOWPLACEMENT WINDOWPLACEMENT
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD ThumbHeight
Definition: registry.h:23
#define error(str)
Definition: mkdosfs.c:1605
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
#define SPI_SETDESKWALLPAPER
Definition: winuser.h:1359
const WCHAR * text
Definition: package.c:1799
#define HKEY_CURRENT_USER
Definition: winreg.h:11
_In_ LPCSTR lpName
Definition: winbase.h:2776
#define SystemParametersInfo
Definition: winuser.h:5848
#define ZeroMemory
Definition: winbase.h:1670
CString strFile2
Definition: registry.h:31
CString strFontName
Definition: registry.h:35
static void SetWallpaper(LPCTSTR szFileName, WallpaperStyle style)
Definition: registry.cpp:42
#define DEFAULT_CHARSET
Definition: wingdi.h:384
CHAR * LPTSTR
Definition: xmlstorage.h:192
DWORD BMPHeight
Definition: registry.h:17
void SetMostRecentFile(LPCTSTR szPathName)
Definition: registry.cpp:187
#define SM_CXSCREEN
Definition: winuser.h:953
void WINAPI SHAddToRecentDocs(UINT uFlags, LPCVOID pv)
Definition: shellord.c:809
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
DWORD NoStretching
Definition: registry.h:20
DWORD ShowThumbnail
Definition: registry.h:21
static void ReadString(CRegKey &key, LPCTSTR lpName, CString &strValue, LPCTSTR lpDefault=TEXT(""))
Definition: registry.cpp:28
DWORD ShowTextTool
Definition: registry.h:43
WINDOWPLACEMENT WindowPlacement
Definition: registry.h:28
DWORD FontsPositionY
Definition: registry.h:42
#define SM_CYSCREEN
Definition: winuser.h:954
#define _T(x)
Definition: vfdio.h:22
DWORD BMPWidth
Definition: registry.h:18
DWORD UnitSetting
Definition: registry.h:27
DWORD ThumbWidth
Definition: registry.h:24
#define MAX_PATH
Definition: compat.h:34
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE)
Definition: atlbase.h:1072
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD PointSize
Definition: registry.h:36
#define GetObject
Definition: wingdi.h:4468
#define DEFAULT_GUI_FONT
Definition: wingdi.h:909
DWORD FontsPositionX
Definition: registry.h:41
DWORD Underline
Definition: registry.h:39
static DWORD ReadDWORD(CRegKey &key, LPCTSTR lpName, DWORD &dwValue, BOOL bCheckForDef)
Definition: registry.cpp:18
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)
Definition: atlbase.h:1093
DWORD ThumbYPos
Definition: registry.h:26
DWORD GridExtent
Definition: registry.h:19
CString strFile1
Definition: registry.h:30
CString strFile4
Definition: registry.h:33
bool IsEmpty() const
Definition: atlsimpstr.h:379
#define SPIF_UPDATEINIFILE
Definition: winuser.h:1561
#define TEXT(s)
Definition: k32.h:26
#define SHARD_PATHW
Definition: shlobj.h:1103
#define SPIF_SENDCHANGE
Definition: winuser.h:1562
DWORD SnapToGrid
Definition: registry.h:22
unsigned int ULONG
Definition: retypes.h:1
CHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:55
static IOleDocumentView * view
Definition: activex.c:1749
Arabic default style
Definition: afstyles.h:93
void LoadPresets()
Definition: registry.cpp:56
Definition: copy.c:22
LONG SetStringValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwType=REG_SZ)
Definition: atlbase.h:1226
CString strFile3
Definition: registry.h:32