ReactOS  0.4.14-dev-843-g15bc263
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 "precomp.h"
11 
12 /* FUNCTIONS *******************************************************************/
13 
15  OUT PDWORD pdwValueData)
16 {
17  HKEY hKey;
18  LONG lResult;
19  DWORD dwValue;
20  DWORD cbData = sizeof(dwValue);
21 
22  /* Initialize the pointer parameter to default */
23  *pdwValueData = 0;
24 
25  /* Open our application's key in order to load its configuration data */
27  L"Software\\Microsoft\\Osk",
28  0,
29  KEY_READ,
30  &hKey);
31 
32  if (lResult != ERROR_SUCCESS)
33  {
34  /* Bail out */
35  DPRINT("LoadDataFromRegistry(): Failed to open the application's key! (Error - %li)\n", lResult);
36  return lResult;
37  }
38 
39  /* Load the specific value based on the parameter caller, lpValueDataName */
40  lResult = RegQueryValueExW(hKey,
41  lpValueDataName,
42  0,
43  0,
44  (BYTE *)&dwValue,
45  &cbData);
46 
47  if (lResult != ERROR_SUCCESS)
48  {
49 
50  /* Bail out */
51  DPRINT("LoadDataFromRegistry(): Failed to load the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
52  RegCloseKey(hKey);
53  return lResult;
54  }
55 
56  /* Is the buffer's size too small to query the required data? */
57  if (cbData != sizeof(dwValue))
58  {
59  /* It is therefore bail out */
60  DPRINT("LoadDataFromRegistry(): The buffer is too small to hold the data!\n");
61  RegCloseKey(hKey);
62  return ERROR_MORE_DATA;
63  }
64 
65  *pdwValueData = dwValue;
66  RegCloseKey(hKey);
67  return lResult;
68 }
69 
71  IN DWORD dwValueData)
72 {
73  HKEY hKey;
74  LONG lResult;
75 
76  /* Set up the application's key in case it has not been made yet */
78  L"Software\\Microsoft\\Osk",
79  0,
80  NULL,
81  0,
82  KEY_WRITE,
83  NULL,
84  &hKey,
85  NULL);
86 
87  if (lResult != ERROR_SUCCESS)
88  {
89  /* Bail out */
90  DPRINT("SaveDataToRegistry(): Failed to create the application's key! (Error - %li)\n", lResult);
91  return lResult;
92  }
93 
94  /* Save the data into the registry value */
95  lResult = RegSetValueExW(hKey,
96  lpValueDataName,
97  0,
98  REG_DWORD,
99  (BYTE *)&dwValueData,
100  sizeof(dwValueData));
101 
102  if (lResult != ERROR_SUCCESS)
103  {
104  /* Bail out */
105  DPRINT("SaveDataToRegistry(): Failed to save the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
106  RegCloseKey(hKey);
107  return lResult;
108  }
109 
110  RegCloseKey(hKey);
111  return lResult;
112 }
113 
115 {
116  DWORD dwValue;
117  LONG lResult;
118 
119  /* Initialize the registry application settings */
120  Globals.bShowWarning = TRUE;
121  Globals.bIsEnhancedKeyboard = TRUE;
122  Globals.bAlwaysOnTop = TRUE;
123  Globals.bSoundClick = FALSE;
124 
125  /* Set the coordinate values to default */
126  Globals.PosX = CW_USEDEFAULT;
127  Globals.PosY = CW_USEDEFAULT;
128 
129  /* Warning dialog registry setting */
130  lResult = LoadDataFromRegistry(L"ShowWarning", &dwValue);
131  if (lResult == NO_ERROR)
132  Globals.bShowWarning = (dwValue != 0);
133 
134  /* Enhanced keyboard switch dialog registry setting */
135  lResult = LoadDataFromRegistry(L"IsEnhancedKeyboard", &dwValue);
136  if (lResult == NO_ERROR)
137  Globals.bIsEnhancedKeyboard = (dwValue != 0);
138 
139  /* Sound on click event registry setting */
140  lResult = LoadDataFromRegistry(L"ClickSound", &dwValue);
141  if (lResult == NO_ERROR)
142  Globals.bSoundClick = (dwValue != 0);
143 
144  /* X coordinate dialog placement registry setting */
145  lResult = LoadDataFromRegistry(L"WindowLeft", &dwValue);
146  if (lResult == NO_ERROR)
147  Globals.PosX = dwValue;
148 
149  /* Y coordinate dialog placement registry setting */
150  lResult = LoadDataFromRegistry(L"WindowTop", &dwValue);
151  if (lResult == NO_ERROR)
152  Globals.PosY = dwValue;
153 
154  /* Top window state registry setting */
155  lResult = LoadDataFromRegistry(L"AlwaysOnTop", &dwValue);
156  if (lResult == NO_ERROR)
157  Globals.bAlwaysOnTop = (dwValue != 0);
158 }
159 
161 {
162  WINDOWPLACEMENT wp;
163 
164  /* Initialize the window placement structure */
165  wp.length = sizeof(WINDOWPLACEMENT);
167 
168  /* Warning dialog registry setting */
169  SaveDataToRegistry(L"ShowWarning", Globals.bShowWarning);
170 
171  /* Enhanced keyboard switch dialog registry setting */
172  SaveDataToRegistry(L"IsEnhancedKeyboard", Globals.bIsEnhancedKeyboard);
173 
174  /* Sound on click event registry setting */
175  SaveDataToRegistry(L"ClickSound", Globals.bSoundClick);
176 
177  /* X coordinate dialog placement registry setting */
178  SaveDataToRegistry(L"WindowLeft", wp.rcNormalPosition.left);
179 
180  /* Y coordinate dialog placement registry setting */
181  SaveDataToRegistry(L"WindowTop", wp.rcNormalPosition.top);
182 
183  /* Top window state registry setting */
184  SaveDataToRegistry(L"AlwaysOnTop", Globals.bAlwaysOnTop);
185 }
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
struct _WINDOWPLACEMENT WINDOWPLACEMENT
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG top
Definition: windef.h:307
LONG LoadDataFromRegistry(IN LPCWSTR lpValueDataName, OUT PDWORD pdwValueData)
Definition: settings.c:14
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
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:4895
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
void SaveSettings(void)
Definition: settings.c:115
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
unsigned char BYTE
Definition: mem.h:68
#define ERROR_MORE_DATA
Definition: dderror.h:13
DWORD * PDWORD
Definition: pedump.c:68
RECT rcNormalPosition
Definition: winuser.h:3270
#define OUT
Definition: typedefs.h:39
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG SaveDataToRegistry(IN LPCWSTR lpValueDataName, IN DWORD dwValueData)
Definition: settings.c:70
#define REG_DWORD
Definition: sdbapi.c:596
void LoadSettings(void)
Definition: settings.c:53