ReactOS  0.4.15-dev-4582-g6dc1738
settings.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS On-Screen Keyboard
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Configuration settings of the application
5  * COPYRIGHT: Copyright 2018-2019 George BiČ™oc (george.bisoc@reactos.org)
6  * Baruch Rutman (peterooch at gmail dot com)
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "precomp.h"
12 
13 /* FUNCTIONS *******************************************************************/
14 
16  OUT PDWORD pdwValueData)
17 {
18  HKEY hKey;
19  LONG lResult;
20  DWORD dwValue;
21  DWORD cbData = sizeof(dwValue);
22 
23  /* Initialize the pointer parameter to default */
24  *pdwValueData = 0;
25 
26  /* Open our application's key in order to load its configuration data */
28  L"Software\\Microsoft\\Osk",
29  0,
30  KEY_READ,
31  &hKey);
32 
33  if (lResult != ERROR_SUCCESS)
34  {
35  /* Bail out */
36  DPRINT("LoadDWORDFromRegistry(): Failed to open the application's key! (Error - %li)\n", lResult);
37  return lResult;
38  }
39 
40  /* Load the specific value based on the parameter caller, lpValueDataName */
41  lResult = RegQueryValueExW(hKey,
42  lpValueDataName,
43  0,
44  0,
45  (BYTE *)&dwValue,
46  &cbData);
47 
48  if (lResult != ERROR_SUCCESS)
49  {
50 
51  /* Bail out */
52  DPRINT("LoadDWORDFromRegistry(): Failed to load the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
54  return lResult;
55  }
56 
57  /* Is the buffer's size too small to query the required data? */
58  if (cbData != sizeof(dwValue))
59  {
60  /* It is therefore bail out */
61  DPRINT("LoadDWORDFromRegistry(): The buffer is too small to hold the data!\n");
63  return ERROR_MORE_DATA;
64  }
65 
66  *pdwValueData = dwValue;
68  return lResult;
69 }
70 
71 /* IN: cchCount is how many characters fit in lpValueData,
72  OUT: cchCount is how many characters were written into lpValueData */
74  OUT LPWSTR lpValueData,
75  IN OUT LPUINT cchCount)
76 {
77  HKEY hKey;
78  LONG lResult;
79  UINT cbCount;
80 
81  cbCount = (*cchCount) * sizeof(WCHAR);
82 
83  /* Open our application's key in order to load its configuration data */
85  L"Software\\Microsoft\\Osk",
86  0,
87  KEY_READ,
88  &hKey);
89 
90  if (lResult != ERROR_SUCCESS)
91  {
92  /* Bail out */
93  DPRINT("LoadStringFromRegistry(): Failed to open the application's key! (Error - %li)\n", lResult);
94  return lResult;
95  }
96 
97  /* Load the specific value based on the parameter caller, lpValueDataName */
98  lResult = RegQueryValueExW(hKey,
99  lpValueDataName,
100  0,
101  0,
102  (BYTE *)lpValueData,
103  (LPDWORD)&cbCount);
104 
105 
106  if (lResult != ERROR_SUCCESS)
107  {
108 
109  /* Bail out */
110  DPRINT("LoadStringFromRegistry(): Failed to load the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
111  RegCloseKey(hKey);
112  return lResult;
113  }
114 
115  *cchCount = cbCount / sizeof(WCHAR);
116 
117  RegCloseKey(hKey);
118  return lResult;
119 }
120 
122  IN DWORD dwValueData)
123 {
124  HKEY hKey;
125  LONG lResult;
126 
127  /* Set up the application's key in case it has not been made yet */
129  L"Software\\Microsoft\\Osk",
130  0,
131  NULL,
132  0,
133  KEY_WRITE,
134  NULL,
135  &hKey,
136  NULL);
137 
138  if (lResult != ERROR_SUCCESS)
139  {
140  /* Bail out */
141  DPRINT("SaveDWORDToRegistry(): Failed to create the application's key! (Error - %li)\n", lResult);
142  return lResult;
143  }
144 
145  /* Save the data into the registry value */
146  lResult = RegSetValueExW(hKey,
147  lpValueDataName,
148  0,
149  REG_DWORD,
150  (BYTE *)&dwValueData,
151  sizeof(dwValueData));
152 
153  if (lResult != ERROR_SUCCESS)
154  {
155  /* Bail out */
156  DPRINT("SaveDWORDToRegistry(): Failed to save the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
157  RegCloseKey(hKey);
158  return lResult;
159  }
160 
161  RegCloseKey(hKey);
162  return lResult;
163 }
164 
166  IN LPCWSTR lpValueData,
167  IN UINT cchCount)
168 {
169  HKEY hKey;
170  LONG lResult;
171 
172  /* Set up the application's key in case it has not been made yet */
174  L"Software\\Microsoft\\Osk",
175  0,
176  NULL,
177  0,
178  KEY_WRITE,
179  NULL,
180  &hKey,
181  NULL);
182 
183  if (lResult != ERROR_SUCCESS)
184  {
185  /* Bail out */
186  DPRINT("SaveStringToRegistry(): Failed to create the application's key! (Error - %li)\n", lResult);
187  return lResult;
188  }
189 
190  /* Save the data into the registry value */
191  lResult = RegSetValueExW(hKey,
192  lpValueDataName,
193  0,
194  REG_SZ,
195  (BYTE *)lpValueData,
196  cchCount * sizeof(WCHAR));
197 
198  if (lResult != ERROR_SUCCESS)
199  {
200  /* Bail out */
201  DPRINT("SaveStringToRegistry(): Failed to save the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
202  RegCloseKey(hKey);
203  return lResult;
204  }
205 
206  RegCloseKey(hKey);
207  return lResult;
208 }
209 
211 {
212  DWORD dwValue;
213  LONG lResult;
214 
215  /* Initialize the registry application settings */
216  Globals.bShowWarning = TRUE;
217  Globals.bIsEnhancedKeyboard = TRUE;
218  Globals.bAlwaysOnTop = TRUE;
219  Globals.bSoundClick = FALSE;
220 
221  /* Set the coordinate values to default */
222  Globals.PosX = CW_USEDEFAULT;
223  Globals.PosY = CW_USEDEFAULT;
224 
225  /* Set font value defaults */
226  Globals.FontHeight = DEFAULT_FONTSIZE;
227 
228  /* Warning dialog registry setting */
229  lResult = LoadDWORDFromRegistry(L"ShowWarning", &dwValue);
230  if (lResult == NO_ERROR)
231  Globals.bShowWarning = (dwValue != 0);
232 
233  /* Enhanced keyboard switch dialog registry setting */
234  lResult = LoadDWORDFromRegistry(L"IsEnhancedKeyboard", &dwValue);
235  if (lResult == NO_ERROR)
236  Globals.bIsEnhancedKeyboard = (dwValue != 0);
237 
238  /* Sound on click event registry setting */
239  lResult = LoadDWORDFromRegistry(L"ClickSound", &dwValue);
240  if (lResult == NO_ERROR)
241  Globals.bSoundClick = (dwValue != 0);
242 
243  /* X coordinate dialog placement registry setting */
244  lResult = LoadDWORDFromRegistry(L"WindowLeft", &dwValue);
245  if (lResult == NO_ERROR)
246  Globals.PosX = dwValue;
247 
248  /* Y coordinate dialog placement registry setting */
249  lResult = LoadDWORDFromRegistry(L"WindowTop", &dwValue);
250  if (lResult == NO_ERROR)
251  Globals.PosY = dwValue;
252 
253  /* Top window state registry setting */
254  lResult = LoadDWORDFromRegistry(L"AlwaysOnTop", &dwValue);
255  if (lResult == NO_ERROR)
256  Globals.bAlwaysOnTop = (dwValue != 0);
257 
258  /* Font information */
259  UINT cchCount = _countof(Globals.FontFaceName);
260  lResult = LoadStringFromRegistry(L"FontFaceName", Globals.FontFaceName, &cchCount);
261 
262  if (lResult != NO_ERROR) /* Copy default on failure */
263  StringCchCopyW(Globals.FontFaceName, _countof(Globals.FontFaceName), L"MS Shell Dlg");
264 
265  lResult = LoadDWORDFromRegistry(L"FontHeight", &dwValue);
266  if (lResult == NO_ERROR)
267  Globals.FontHeight = dwValue;
268 }
269 
271 {
272  WINDOWPLACEMENT wp;
273 
274  /* Initialize the window placement structure */
275  wp.length = sizeof(WINDOWPLACEMENT);
277 
278  /* Warning dialog registry setting */
279  SaveDWORDToRegistry(L"ShowWarning", Globals.bShowWarning);
280 
281  /* Enhanced keyboard switch dialog registry setting */
282  SaveDWORDToRegistry(L"IsEnhancedKeyboard", Globals.bIsEnhancedKeyboard);
283 
284  /* Sound on click event registry setting */
285  SaveDWORDToRegistry(L"ClickSound", Globals.bSoundClick);
286 
287  /* X coordinate dialog placement registry setting */
288  SaveDWORDToRegistry(L"WindowLeft", wp.rcNormalPosition.left);
289 
290  /* Y coordinate dialog placement registry setting */
291  SaveDWORDToRegistry(L"WindowTop", wp.rcNormalPosition.top);
292 
293  /* Top window state registry setting */
294  SaveDWORDToRegistry(L"AlwaysOnTop", Globals.bAlwaysOnTop);
295 
296  /* Font information */
297  SaveStringToRegistry(L"FontFaceName", Globals.FontFaceName, _countof(Globals.FontFaceName));
298  SaveDWORDToRegistry(L"FontHeight", Globals.FontHeight);
299 }
#define IN
Definition: typedefs.h:39
LONG LoadDWORDFromRegistry(IN LPCWSTR lpValueDataName, OUT PDWORD pdwValueData)
Definition: settings.c:15
struct _WINDOWPLACEMENT WINDOWPLACEMENT
#define ERROR_SUCCESS
Definition: deptool.c:10
static int cbCount
Definition: fiber.c:42
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG top
Definition: windef.h:307
uint32_t * LPUINT
Definition: typedefs.h:59
LONG SaveStringToRegistry(IN LPCWSTR lpValueDataName, IN LPCWSTR lpValueData, IN UINT cchCount)
Definition: settings.c:165
LONG SaveDWORDToRegistry(IN LPCWSTR lpValueDataName, IN DWORD dwValueData)
Definition: settings.c:121
LONG left
Definition: windef.h:306
#define NO_ERROR
Definition: dderror.h:5
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define CW_USEDEFAULT
Definition: winuser.h:225
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4899
LONG LoadStringFromRegistry(IN LPCWSTR lpValueDataName, OUT LPWSTR lpValueData, IN OUT LPUINT cchCount)
Definition: settings.c:73
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4120
void SaveSettings(void)
Definition: settings.c:115
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_MORE_DATA
Definition: dderror.h:13
unsigned char BYTE
Definition: xxhash.c:193
#define DEFAULT_FONTSIZE
Definition: precomp.h:127
FxAutoRegKey hKey
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
DWORD * PDWORD
Definition: pedump.c:68
RECT rcNormalPosition
Definition: winuser.h:3275
#define OUT
Definition: typedefs.h:40
uint32_t * LPDWORD
Definition: typedefs.h:59
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
#define DPRINT
Definition: sndvol32.h:71
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define REG_DWORD
Definition: sdbapi.c:596
#define RegCloseKey(hKey)
Definition: registry.h:47
void LoadSettings(void)
Definition: settings.c:53
#define REG_SZ
Definition: layer.c:22