ReactOS  0.4.13-dev-235-g7373cb3
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 BiČ™oc George (fraizeraust99 at gmail dot com)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include "osk.h"
11 #include "settings.h"
12 
13 /* FUNCTIONS *******************************************************************/
14 
16 {
17  HKEY hKey;
18  LONG lResult;
19  DWORD dwShowWarningData, dwLayout, dwSoundOnClick, dwPositionLeft, dwPositionTop;
20  DWORD cbData = sizeof(DWORD);
21 
22  /* Set the structure members to TRUE (and the bSoundClick member to FALSE) */
23  Globals.bShowWarning = TRUE;
24  Globals.bIsEnhancedKeyboard = TRUE;
25  Globals.bSoundClick = FALSE;
26 
27  /* Set the coordinate values to default */
28  Globals.PosX = CW_USEDEFAULT;
29  Globals.PosY = CW_USEDEFAULT;
30 
31  /* Open the key, so that we can query it */
33  L"Software\\Microsoft\\Osk",
34  0,
35  KEY_READ,
36  &hKey);
37 
38  if (lResult != ERROR_SUCCESS)
39  {
40  /* Bail out and return FALSE if we fail */
41  return FALSE;
42  }
43 
44  /* Query the key */
45  lResult = RegQueryValueExW(hKey,
46  L"ShowWarning",
47  0,
48  0,
49  (BYTE *)&dwShowWarningData,
50  &cbData);
51 
52  if (lResult != ERROR_SUCCESS)
53  {
54  /* Bail out and return FALSE if we fail */
55  RegCloseKey(hKey);
56  return FALSE;
57  }
58 
59  /* Load the data value (it can be either FALSE or TRUE depending on the data itself) */
60  Globals.bShowWarning = (dwShowWarningData != 0);
61 
62  /* Query the key */
63  lResult = RegQueryValueExW(hKey,
64  L"IsEnhancedKeyboard",
65  0,
66  0,
67  (BYTE *)&dwLayout,
68  &cbData);
69 
70  if (lResult != ERROR_SUCCESS)
71  {
72  /* Bail out and return FALSE if we fail */
73  RegCloseKey(hKey);
74  return FALSE;
75  }
76 
77  /* Load the dialog layout value */
78  Globals.bIsEnhancedKeyboard = (dwLayout != 0);
79 
80  /* Query the key */
81  lResult = RegQueryValueExW(hKey,
82  L"ClickSound",
83  0,
84  0,
85  (BYTE *)&dwSoundOnClick,
86  &cbData);
87 
88  if (lResult != ERROR_SUCCESS)
89  {
90  /* Bail out and return FALSE if we fail */
91  RegCloseKey(hKey);
92  return FALSE;
93  }
94 
95  /* Load the sound on click value event */
96  Globals.bSoundClick = (dwSoundOnClick != 0);
97 
98  /* Query the key */
99  lResult = RegQueryValueExW(hKey,
100  L"WindowLeft",
101  0,
102  0,
103  (BYTE *)&dwPositionLeft,
104  &cbData);
105 
106  if (lResult != ERROR_SUCCESS)
107  {
108  /* Bail out and return FALSE if we fail */
109  RegCloseKey(hKey);
110  return FALSE;
111  }
112 
113  /* Load the X value data of the dialog's coordinate */
114  Globals.PosX = dwPositionLeft;
115 
116  lResult = RegQueryValueExW(hKey,
117  L"WindowTop",
118  0,
119  0,
120  (BYTE *)&dwPositionTop,
121  &cbData);
122 
123  if (lResult != ERROR_SUCCESS)
124  {
125  /* Bail out and return FALSE if we fail */
126  RegCloseKey(hKey);
127  return FALSE;
128  }
129 
130  /* Load the Y value data of the dialog's coordinate */
131  Globals.PosY = dwPositionTop;
132 
133  /* If we're here then we succeed, close the key and return TRUE */
134  RegCloseKey(hKey);
135  return TRUE;
136 }
137 
139 {
140  HKEY hKey;
141  LONG lResult;
142  DWORD dwShowWarningData, dwLayout, dwSoundOnClick, dwPositionLeft, dwPositionTop;
143  WINDOWPLACEMENT wp;
144 
145  /* Set the structure length and retrieve the dialog's placement */
146  wp.length = sizeof(WINDOWPLACEMENT);
148 
149  /* If no key has been made, create one */
151  L"Software\\Microsoft\\Osk",
152  0,
153  NULL,
154  0,
155  KEY_WRITE,
156  NULL,
157  &hKey,
158  NULL);
159 
160  if (lResult != ERROR_SUCCESS)
161  {
162  /* Bail out and return FALSE if we fail */
163  return FALSE;
164  }
165 
166  /* The data value of the subkey will be appended to the warning dialog switch */
167  dwShowWarningData = Globals.bShowWarning;
168 
169  /* Welcome warning box value key */
170  lResult = RegSetValueExW(hKey,
171  L"ShowWarning",
172  0,
173  REG_DWORD,
174  (BYTE *)&dwShowWarningData,
175  sizeof(dwShowWarningData));
176 
177  if (lResult != ERROR_SUCCESS)
178  {
179  /* Bail out and return FALSE if we fail */
180  RegCloseKey(hKey);
181  return FALSE;
182  }
183 
184  /* The value will be appended to the layout dialog */
185  dwLayout = Globals.bIsEnhancedKeyboard;
186 
187  /* Keyboard dialog switcher */
188  lResult = RegSetValueExW(hKey,
189  L"IsEnhancedKeyboard",
190  0,
191  REG_DWORD,
192  (BYTE *)&dwLayout,
193  sizeof(dwLayout));
194 
195  if (lResult != ERROR_SUCCESS)
196  {
197  /* Bail out and return FALSE if we fail */
198  RegCloseKey(hKey);
199  return FALSE;
200  }
201 
202  /* The value will be appended to the sound on click event */
203  dwSoundOnClick = Globals.bSoundClick;
204 
205  /* "Sound on Click" switcher value key */
206  lResult = RegSetValueExW(hKey,
207  L"ClickSound",
208  0,
209  REG_DWORD,
210  (BYTE *)&dwSoundOnClick,
211  sizeof(dwSoundOnClick));
212 
213  if (lResult != ERROR_SUCCESS)
214  {
215  /* Bail out and return FALSE if we fail */
216  RegCloseKey(hKey);
217  return FALSE;
218  }
219 
220  /* The value will be appended to the X coordination dialog's placement */
221  dwPositionLeft = wp.rcNormalPosition.left;
222 
223  /* Position X coordination of dialog's placement value key */
224  lResult = RegSetValueExW(hKey,
225  L"WindowLeft",
226  0,
227  REG_DWORD,
228  (BYTE *)&dwPositionLeft,
229  sizeof(dwPositionLeft));
230 
231  if (lResult != ERROR_SUCCESS)
232  {
233  /* Bail out and return FALSE if we fail */
234  RegCloseKey(hKey);
235  return FALSE;
236  }
237 
238  /* The value will be appended to the Y coordination dialog's placement */
239  dwPositionTop = wp.rcNormalPosition.top;
240 
241  /* Position Y coordination of dialog's placement value key */
242  lResult = RegSetValueExW(hKey,
243  L"WindowTop",
244  0,
245  REG_DWORD,
246  (BYTE *)&dwPositionTop,
247  sizeof(dwPositionTop));
248 
249  if (lResult != ERROR_SUCCESS)
250  {
251  /* Bail out and return FALSE if we fail */
252  RegCloseKey(hKey);
253  return FALSE;
254  }
255 
256  /* If we're here then we succeed, close the key and return TRUE */
257  RegCloseKey(hKey);
258  return TRUE;
259 }
#define TRUE
Definition: types.h:120
struct _WINDOWPLACEMENT WINDOWPLACEMENT
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG top
Definition: windef.h:292
LONG left
Definition: windef.h:291
#define DWORD
Definition: nt_native.h:44
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:1094
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
BOOL LoadDataFromRegistry()
Definition: settings.c:15
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:4917
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL SaveDataToRegistry()
Definition: settings.c:138
static const WCHAR L[]
Definition: oid.c:1250
unsigned char BYTE
Definition: mem.h:68
RECT rcNormalPosition
Definition: winuser.h:3237
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define REG_DWORD
Definition: sdbapi.c:596