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

Go to the source code of this file.

Functions

LONG LoadDataFromRegistry (IN LPCWSTR lpValueDataName, OUT PDWORD pdwValueData)
 
LONG SaveDataToRegistry (IN LPCWSTR lpValueDataName, IN DWORD dwValueData)
 
VOID LoadSettings (VOID)
 
VOID SaveSettings (VOID)
 

Function Documentation

◆ LoadDataFromRegistry()

LONG LoadDataFromRegistry ( IN LPCWSTR  lpValueDataName,
OUT PDWORD  pdwValueData 
)

Definition at line 14 of file settings.c.

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);
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");
62  return ERROR_MORE_DATA;
63  }
64 
65  *pdwValueData = dwValue;
67  return lResult;
68 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
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
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define ERROR_MORE_DATA
Definition: dderror.h:13
unsigned char BYTE
Definition: xxhash.c:193
FxAutoRegKey hKey
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define DPRINT
Definition: sndvol32.h:71

Referenced by LoadSettings().

◆ LoadSettings()

VOID LoadSettings ( VOID  )

Definition at line 114 of file settings.c.

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 }
#define TRUE
Definition: types.h:120
LONG LoadDataFromRegistry(IN LPCWSTR lpValueDataName, OUT PDWORD pdwValueData)
Definition: settings.c:14
#define NO_ERROR
Definition: dderror.h:5
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define CW_USEDEFAULT
Definition: winuser.h:225
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250

◆ SaveDataToRegistry()

LONG SaveDataToRegistry ( IN LPCWSTR  lpValueDataName,
IN DWORD  dwValueData 
)

Definition at line 70 of file settings.c.

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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
#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
static const WCHAR L[]
Definition: oid.c:1250
unsigned char BYTE
Definition: xxhash.c:193
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
#define DPRINT
Definition: sndvol32.h:71
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by SaveSettings().

◆ SaveSettings()

VOID SaveSettings ( VOID  )

Definition at line 160 of file settings.c.

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 }
struct _WINDOWPLACEMENT WINDOWPLACEMENT
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
static const WCHAR L[]
Definition: oid.c:1250
RECT rcNormalPosition
Definition: winuser.h:3270
LONG SaveDataToRegistry(IN LPCWSTR lpValueDataName, IN DWORD dwValueData)
Definition: settings.c:70