ReactOS  0.4.12-dev-43-g63b00d8
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  */
8 
9 /* INCLUDES *********************************************************/
10 
11 #include "precomp.h"
12 
13 #include <winreg.h>
14 
15 /* FUNCTIONS ********************************************************/
16 static DWORD ReadDWORD(CRegKey &key, LPCTSTR lpName, DWORD &dwValue, BOOL bCheckForDef)
17 {
18  DWORD dwPrev = dwValue;
19 
20  if (key.QueryDWORDValue(lpName, dwValue) != ERROR_SUCCESS)
21  dwValue = dwPrev;
22 
23  if (bCheckForDef && dwValue == 0)
24  dwValue = dwPrev;
25 
26  return dwPrev;
27 }
28 
29 static void ReadFileHistory(CRegKey &key, LPCTSTR lpName, CString &strFile)
30 {
31  ULONG nChars = MAX_PATH;
32  LPTSTR szFile = strFile.GetBuffer(nChars);
33  if (key.QueryStringValue(lpName, szFile, &nChars) != ERROR_SUCCESS)
34  szFile[0] = '\0';
35  strFile.ReleaseBuffer();
36 }
37 
39 {
40  CRegKey desktop;
41  if (desktop.Open(HKEY_CURRENT_USER, _T("Control Panel\\Desktop")) == ERROR_SUCCESS)
42  {
43  desktop.SetStringValue(_T("Wallpaper"), szFileName);
44 
45  desktop.SetStringValue(_T("WallpaperStyle"), (style == RegistrySettings::STRETCHED) ? _T("2") : _T("0"));
46  desktop.SetStringValue(_T("TileWallpaper"), (style == RegistrySettings::TILED) ? _T("1") : _T("0"));
47  }
48 
50 }
51 
53 {
54  BMPHeight = 300;
55  BMPWidth = 400;
56  GridExtent = 1;
57  NoStretching = 0;
58  ShowThumbnail = 0;
59  SnapToGrid = 0;
60  ThumbHeight = 100;
61  ThumbWidth = 120;
62  ThumbXPos = 180;
63  ThumbYPos = 200;
64  UnitSetting = 0;
65  const WINDOWPLACEMENT DefaultWindowPlacement = {
66  sizeof(WINDOWPLACEMENT),
67  0,
69  {0, 0},
70  {-1, -1},
71  {100, 100, 700, 550}
72  };
73  WindowPlacement = DefaultWindowPlacement;
74 }
75 
77 {
78  LoadPresets();
79 
80  CRegKey view;
81  if (view.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), KEY_READ) == ERROR_SUCCESS)
82  {
83  ReadDWORD(view, _T("BMPHeight"), BMPHeight, TRUE);
84  ReadDWORD(view, _T("BMPWidth"), BMPWidth, TRUE);
85  ReadDWORD(view, _T("GridExtent"), GridExtent, FALSE);
86  ReadDWORD(view, _T("NoStretching"), NoStretching, FALSE);
87  ReadDWORD(view, _T("ShowThumbnail"), ShowThumbnail, FALSE);
88  ReadDWORD(view, _T("SnapToGrid"), SnapToGrid, FALSE);
89  ReadDWORD(view, _T("ThumbHeight"), ThumbHeight, TRUE);
90  ReadDWORD(view, _T("ThumbWidth"), ThumbWidth, TRUE);
91  ReadDWORD(view, _T("ThumbXPos"), ThumbXPos, TRUE);
92  ReadDWORD(view, _T("ThumbYPos"), ThumbYPos, TRUE);
93  ReadDWORD(view, _T("UnitSetting"), UnitSetting, FALSE);
94 
95  ULONG pnBytes = sizeof(WINDOWPLACEMENT);
96  view.QueryBinaryValue(_T("WindowPlacement"), &WindowPlacement, &pnBytes);
97  }
98 
99  CRegKey files;
100  if (files.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), KEY_READ) == ERROR_SUCCESS)
101  {
102  ReadFileHistory(files, _T("File1"), strFile1);
103  ReadFileHistory(files, _T("File2"), strFile2);
104  ReadFileHistory(files, _T("File3"), strFile3);
105  ReadFileHistory(files, _T("File4"), strFile4);
106  }
107 }
108 
110 {
111  CRegKey view;
112  if (view.Create(HKEY_CURRENT_USER,
113  _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View")) == ERROR_SUCCESS)
114  {
115  view.SetDWORDValue(_T("BMPHeight"), BMPHeight);
116  view.SetDWORDValue(_T("BMPWidth"), BMPWidth);
117  view.SetDWORDValue(_T("GridExtent"), GridExtent);
118  view.SetDWORDValue(_T("NoStretching"), NoStretching);
119  view.SetDWORDValue(_T("ShowThumbnail"), ShowThumbnail);
120  view.SetDWORDValue(_T("SnapToGrid"), SnapToGrid);
121  view.SetDWORDValue(_T("ThumbHeight"), ThumbHeight);
122  view.SetDWORDValue(_T("ThumbWidth"), ThumbWidth);
123  view.SetDWORDValue(_T("ThumbXPos"), ThumbXPos);
124  view.SetDWORDValue(_T("ThumbYPos"), ThumbYPos);
125  view.SetDWORDValue(_T("UnitSetting"), UnitSetting);
126 
127  view.SetBinaryValue(_T("WindowPlacement"), &WindowPlacement, sizeof(WINDOWPLACEMENT));
128  }
129 
130  CRegKey files;
131  if (files.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List")) == ERROR_SUCCESS)
132  {
133  if (!strFile1.IsEmpty())
134  files.SetStringValue(_T("File1"), strFile1);
135  if (!strFile2.IsEmpty())
136  files.SetStringValue(_T("File2"), strFile2);
137  if (!strFile3.IsEmpty())
138  files.SetStringValue(_T("File3"), strFile3);
139  if (!strFile4.IsEmpty())
140  files.SetStringValue(_T("File4"), strFile4);
141  }
142 }
143 
145 {
146  if (strFile1 == szPathName)
147  {
148  // do nothing
149  }
150  else if (strFile2 == szPathName)
151  {
152  CString strTemp = strFile2;
153  strFile2 = strFile1;
154  strFile1 = strTemp;
155  }
156  else if (strFile3 == szPathName)
157  {
158  CString strTemp = strFile3;
159  strFile3 = strFile2;
160  strFile2 = strFile1;
161  strFile1 = strTemp;
162  }
163  else if (strFile4 == szPathName)
164  {
165  CString strTemp = strFile4;
166  strFile4 = strFile3;
167  strFile3 = strFile2;
168  strFile2 = strFile1;
169  strFile1 = strTemp;
170  }
171  else
172  {
173  strFile4 = strFile3;
174  strFile3 = strFile2;
175  strFile2 = strFile1;
176  strFile1 = szPathName;
177  }
178 }
LONG QueryBinaryValue(LPCTSTR pszValueName, void *pValue, ULONG *pnBytes)
Definition: atlbase.h:1146
DWORD ThumbXPos
Definition: registry.h:25
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
struct _WINDOWPLACEMENT WINDOWPLACEMENT
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD ThumbHeight
Definition: registry.h:23
#define KEY_READ
Definition: nt_native.h:1023
#define SPI_SETDESKWALLPAPER
Definition: winuser.h:1351
#define HKEY_CURRENT_USER
Definition: winreg.h:11
_In_ LPCSTR lpName
Definition: winbase.h:2729
#define SystemParametersInfo
Definition: winuser.h:5724
LONG SetBinaryValue(LPCTSTR pszValueName, const void *pValue, ULONG nBytes)
Definition: atlbase.h:1261
CString strFile2
Definition: registry.h:31
static void SetWallpaper(LPCTSTR szFileName, WallpaperStyle style)
Definition: registry.cpp:38
CHAR * LPTSTR
Definition: xmlstorage.h:192
DWORD BMPHeight
Definition: registry.h:17
void SetMostRecentFile(LPCTSTR szPathName)
Definition: registry.cpp:144
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
static void ReadFileHistory(CRegKey &key, LPCTSTR lpName, CString &strFile)
Definition: registry.cpp:29
DWORD NoStretching
Definition: registry.h:20
DWORD ShowThumbnail
Definition: registry.h:21
LONG QueryDWORDValue(LPCTSTR pszValueName, DWORD &dwValue)
Definition: atlbase.h:1134
WINDOWPLACEMENT WindowPlacement
Definition: registry.h:28
#define _T(x)
Definition: vfdio.h:22
DWORD BMPWidth
Definition: registry.h:18
LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue)
Definition: atlbase.h:1227
#define SPIF_SENDWININICHANGE
Definition: winuser.h:1554
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD UnitSetting
Definition: registry.h:27
DWORD ThumbWidth
Definition: registry.h:24
#define MAX_PATH
Definition: compat.h:26
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE)
Definition: atlbase.h:1078
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG QueryStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG *pnChars)
Definition: atlbase.h:1157
static DWORD ReadDWORD(CRegKey &key, LPCTSTR lpName, DWORD &dwValue, BOOL bCheckForDef)
Definition: registry.cpp:16
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:1099
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:1553
#define SW_SHOWNORMAL
Definition: winuser.h:764
DWORD SnapToGrid
Definition: registry.h:22
unsigned int ULONG
Definition: retypes.h:1
static IOleDocumentView * view
Definition: activex.c:1749
Arabic default style
Definition: afstyles.h:93
void LoadPresets()
Definition: registry.cpp:52
Definition: path.c:42
LONG SetStringValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwType=REG_SZ)
Definition: atlbase.h:1232
CString strFile3
Definition: registry.h:32