ReactOS 0.4.15-dev-7994-gb388cb6
settings.c File Reference
#include "precomp.h"
Include dependency graph for settings.c:

Go to the source code of this file.

Functions

LONG LoadDWORDFromRegistry (IN LPCWSTR lpValueDataName, OUT PDWORD pdwValueData)
 
LONG LoadStringFromRegistry (IN LPCWSTR lpValueDataName, OUT LPWSTR lpValueData, IN OUT LPUINT cchCount)
 
LONG SaveDWORDToRegistry (IN LPCWSTR lpValueDataName, IN DWORD dwValueData)
 
LONG SaveStringToRegistry (IN LPCWSTR lpValueDataName, IN LPCWSTR lpValueData, IN UINT cchCount)
 
VOID LoadSettings (VOID)
 
VOID SaveSettings (VOID)
 

Function Documentation

◆ LoadDWORDFromRegistry()

LONG LoadDWORDFromRegistry ( IN LPCWSTR  lpValueDataName,
OUT PDWORD  pdwValueData 
)

Definition at line 15 of file settings.c.

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,
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}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define KEY_READ
Definition: nt_native.h:1023
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define DPRINT
Definition: sndvol32.h:71
#define HKEY_CURRENT_USER
Definition: winreg.h:11
unsigned char BYTE
Definition: xxhash.c:193

Referenced by LoadSettings().

◆ LoadSettings()

VOID LoadSettings ( VOID  )

Definition at line 210 of file settings.c.

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}
#define DEFAULT_FONTSIZE
Definition: precomp.h:125
LONG LoadStringFromRegistry(IN LPCWSTR lpValueDataName, OUT LPWSTR lpValueData, IN OUT LPUINT cchCount)
Definition: settings.c:73
LONG LoadDWORDFromRegistry(IN LPCWSTR lpValueDataName, OUT PDWORD pdwValueData)
Definition: settings.c:15
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define NO_ERROR
Definition: dderror.h:5
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int UINT
Definition: ndis.h:50
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define CW_USEDEFAULT
Definition: winuser.h:225

◆ LoadStringFromRegistry()

LONG LoadStringFromRegistry ( IN LPCWSTR  lpValueDataName,
OUT LPWSTR  lpValueData,
IN OUT LPUINT  cchCount 
)

Definition at line 73 of file settings.c.

76{
77 HKEY hKey;
78 LONG lResult;
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,
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);
112 return lResult;
113 }
114
115 *cchCount = cbCount / sizeof(WCHAR);
116
118 return lResult;
119}
static int cbCount
Definition: fiber.c:42
uint32_t * LPDWORD
Definition: typedefs.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by LoadSettings().

◆ SaveDWORDToRegistry()

LONG SaveDWORDToRegistry ( IN LPCWSTR  lpValueDataName,
IN DWORD  dwValueData 
)

Definition at line 121 of file settings.c.

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);
158 return lResult;
159 }
160
162 return lResult;
163}
#define NULL
Definition: types.h:112
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:1096
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:4882
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by SaveSettings().

◆ SaveSettings()

VOID SaveSettings ( VOID  )

Definition at line 270 of file settings.c.

271{
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 */
289
290 /* Y coordinate dialog placement registry setting */
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}
LONG SaveDWORDToRegistry(IN LPCWSTR lpValueDataName, IN DWORD dwValueData)
Definition: settings.c:121
LONG SaveStringToRegistry(IN LPCWSTR lpValueDataName, IN LPCWSTR lpValueData, IN UINT cchCount)
Definition: settings.c:165
RECT rcNormalPosition
Definition: winuser.h:3295
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
struct _WINDOWPLACEMENT WINDOWPLACEMENT

◆ SaveStringToRegistry()

LONG SaveStringToRegistry ( IN LPCWSTR  lpValueDataName,
IN LPCWSTR  lpValueData,
IN UINT  cchCount 
)

Definition at line 165 of file settings.c.

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);
203 return lResult;
204 }
205
207 return lResult;
208}
#define REG_SZ
Definition: layer.c:22

Referenced by SaveSettings().