2018-11-17 20:27:33 +00:00
|
|
|
|
/*
|
|
|
|
|
* PROJECT: ReactOS On-Screen Keyboard
|
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2019-03-02 17:10:26 +00:00
|
|
|
|
* PURPOSE: Configuration settings of the application
|
2021-02-22 15:26:55 +00:00
|
|
|
|
* COPYRIGHT: Copyright 2018-2019 George Bișoc (george.bisoc@reactos.org)
|
2021-08-11 19:36:30 +00:00
|
|
|
|
* Baruch Rutman (peterooch at gmail dot com)
|
2018-11-17 20:27:33 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
2019-07-16 15:35:30 +00:00
|
|
|
|
#include "precomp.h"
|
2018-11-17 20:27:33 +00:00
|
|
|
|
|
|
|
|
|
/* FUNCTIONS *******************************************************************/
|
|
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
|
LONG LoadDWORDFromRegistry(IN LPCWSTR lpValueDataName,
|
|
|
|
|
OUT PDWORD pdwValueData)
|
2018-11-17 20:27:33 +00:00
|
|
|
|
{
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
LONG lResult;
|
2019-07-16 15:35:30 +00:00
|
|
|
|
DWORD dwValue;
|
2019-11-18 20:25:51 +00:00
|
|
|
|
DWORD cbData = sizeof(dwValue);
|
2018-11-17 20:27:33 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Initialize the pointer parameter to default */
|
|
|
|
|
*pdwValueData = 0;
|
2019-03-02 17:10:26 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Open our application's key in order to load its configuration data */
|
2018-11-17 20:27:33 +00:00
|
|
|
|
lResult = RegOpenKeyExW(HKEY_CURRENT_USER,
|
2019-03-02 17:10:26 +00:00
|
|
|
|
L"Software\\Microsoft\\Osk",
|
2018-11-17 20:27:33 +00:00
|
|
|
|
0,
|
|
|
|
|
KEY_READ,
|
|
|
|
|
&hKey);
|
|
|
|
|
|
|
|
|
|
if (lResult != ERROR_SUCCESS)
|
|
|
|
|
{
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Bail out */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
DPRINT("LoadDWORDFromRegistry(): Failed to open the application's key! (Error - %li)\n", lResult);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
return lResult;
|
2019-02-24 15:40:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Load the specific value based on the parameter caller, lpValueDataName */
|
2019-03-02 17:10:26 +00:00
|
|
|
|
lResult = RegQueryValueExW(hKey,
|
2019-12-11 23:25:55 +00:00
|
|
|
|
lpValueDataName,
|
2019-03-02 17:10:26 +00:00
|
|
|
|
0,
|
|
|
|
|
0,
|
2019-07-16 15:35:30 +00:00
|
|
|
|
(BYTE *)&dwValue,
|
2019-03-02 17:10:26 +00:00
|
|
|
|
&cbData);
|
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
if (lResult != ERROR_SUCCESS)
|
2019-03-02 17:10:26 +00:00
|
|
|
|
{
|
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Bail out */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
DPRINT("LoadDWORDFromRegistry(): Failed to load the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
|
2019-03-02 17:10:26 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
return lResult;
|
2019-03-02 17:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Is the buffer's size too small to query the required data? */
|
|
|
|
|
if (cbData != sizeof(dwValue))
|
2019-07-15 13:59:06 +00:00
|
|
|
|
{
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* It is therefore bail out */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
DPRINT("LoadDWORDFromRegistry(): The buffer is too small to hold the data!\n");
|
2019-07-15 13:59:06 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
return ERROR_MORE_DATA;
|
2019-07-15 13:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
*pdwValueData = dwValue;
|
2018-11-17 20:27:33 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
return lResult;
|
2018-11-17 20:27:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
|
/* IN: cchCount is how many characters fit in lpValueData,
|
|
|
|
|
OUT: cchCount is how many characters were written into lpValueData */
|
|
|
|
|
LONG LoadStringFromRegistry(IN LPCWSTR lpValueDataName,
|
|
|
|
|
OUT LPWSTR lpValueData,
|
|
|
|
|
IN OUT LPUINT cchCount)
|
|
|
|
|
{
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
LONG lResult;
|
|
|
|
|
UINT cbCount;
|
|
|
|
|
|
|
|
|
|
cbCount = (*cchCount) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
|
|
/* Open our application's key in order to load its configuration data */
|
|
|
|
|
lResult = RegOpenKeyExW(HKEY_CURRENT_USER,
|
|
|
|
|
L"Software\\Microsoft\\Osk",
|
|
|
|
|
0,
|
|
|
|
|
KEY_READ,
|
|
|
|
|
&hKey);
|
|
|
|
|
|
|
|
|
|
if (lResult != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
/* Bail out */
|
|
|
|
|
DPRINT("LoadStringFromRegistry(): Failed to open the application's key! (Error - %li)\n", lResult);
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Load the specific value based on the parameter caller, lpValueDataName */
|
|
|
|
|
lResult = RegQueryValueExW(hKey,
|
|
|
|
|
lpValueDataName,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
(BYTE *)lpValueData,
|
|
|
|
|
(LPDWORD)&cbCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lResult != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/* Bail out */
|
|
|
|
|
DPRINT("LoadStringFromRegistry(): Failed to load the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*cchCount = cbCount / sizeof(WCHAR);
|
|
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LONG SaveDWORDToRegistry(IN LPCWSTR lpValueDataName,
|
|
|
|
|
IN DWORD dwValueData)
|
2018-11-17 20:27:33 +00:00
|
|
|
|
{
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
LONG lResult;
|
2019-03-02 17:10:26 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Set up the application's key in case it has not been made yet */
|
2018-11-17 20:27:33 +00:00
|
|
|
|
lResult = RegCreateKeyExW(HKEY_CURRENT_USER,
|
2019-03-02 17:10:26 +00:00
|
|
|
|
L"Software\\Microsoft\\Osk",
|
2018-11-17 20:27:33 +00:00
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
0,
|
|
|
|
|
KEY_WRITE,
|
|
|
|
|
NULL,
|
|
|
|
|
&hKey,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (lResult != ERROR_SUCCESS)
|
|
|
|
|
{
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Bail out */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
DPRINT("SaveDWORDToRegistry(): Failed to create the application's key! (Error - %li)\n", lResult);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
return lResult;
|
2019-02-10 15:04:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Save the data into the registry value */
|
2019-02-10 15:04:16 +00:00
|
|
|
|
lResult = RegSetValueExW(hKey,
|
2019-12-11 23:25:55 +00:00
|
|
|
|
lpValueDataName,
|
2019-02-10 15:04:16 +00:00
|
|
|
|
0,
|
|
|
|
|
REG_DWORD,
|
2019-12-11 23:25:55 +00:00
|
|
|
|
(BYTE *)&dwValueData,
|
|
|
|
|
sizeof(dwValueData));
|
2018-11-17 20:27:33 +00:00
|
|
|
|
|
|
|
|
|
if (lResult != ERROR_SUCCESS)
|
|
|
|
|
{
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Bail out */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
DPRINT("SaveDWORDToRegistry(): Failed to save the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LONG SaveStringToRegistry(IN LPCWSTR lpValueDataName,
|
|
|
|
|
IN LPCWSTR lpValueData,
|
|
|
|
|
IN UINT cchCount)
|
|
|
|
|
{
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
LONG lResult;
|
|
|
|
|
|
|
|
|
|
/* Set up the application's key in case it has not been made yet */
|
|
|
|
|
lResult = RegCreateKeyExW(HKEY_CURRENT_USER,
|
|
|
|
|
L"Software\\Microsoft\\Osk",
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
0,
|
|
|
|
|
KEY_WRITE,
|
|
|
|
|
NULL,
|
|
|
|
|
&hKey,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (lResult != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
/* Bail out */
|
|
|
|
|
DPRINT("SaveStringToRegistry(): Failed to create the application's key! (Error - %li)\n", lResult);
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Save the data into the registry value */
|
|
|
|
|
lResult = RegSetValueExW(hKey,
|
|
|
|
|
lpValueDataName,
|
|
|
|
|
0,
|
|
|
|
|
REG_SZ,
|
|
|
|
|
(BYTE *)lpValueData,
|
|
|
|
|
cchCount * sizeof(WCHAR));
|
|
|
|
|
|
|
|
|
|
if (lResult != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
/* Bail out */
|
|
|
|
|
DPRINT("SaveStringToRegistry(): Failed to save the following value - \"%S\". (Error - %li)\n", lpValueDataName, lResult);
|
2018-11-17 20:27:33 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
return lResult;
|
2018-11-17 20:27:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
2019-02-24 15:40:02 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
VOID LoadSettings(VOID)
|
|
|
|
|
{
|
|
|
|
|
DWORD dwValue;
|
|
|
|
|
LONG lResult;
|
2019-02-24 15:40:02 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Initialize the registry application settings */
|
|
|
|
|
Globals.bShowWarning = TRUE;
|
|
|
|
|
Globals.bIsEnhancedKeyboard = TRUE;
|
|
|
|
|
Globals.bAlwaysOnTop = TRUE;
|
|
|
|
|
Globals.bSoundClick = FALSE;
|
2019-02-24 15:40:02 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Set the coordinate values to default */
|
|
|
|
|
Globals.PosX = CW_USEDEFAULT;
|
|
|
|
|
Globals.PosY = CW_USEDEFAULT;
|
2019-03-02 17:10:26 +00:00
|
|
|
|
|
2021-08-11 19:36:30 +00:00
|
|
|
|
/* Set font value defaults */
|
|
|
|
|
Globals.FontHeight = DEFAULT_FONTSIZE;
|
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Warning dialog registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
lResult = LoadDWORDFromRegistry(L"ShowWarning", &dwValue);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
if (lResult == NO_ERROR)
|
|
|
|
|
Globals.bShowWarning = (dwValue != 0);
|
|
|
|
|
|
|
|
|
|
/* Enhanced keyboard switch dialog registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
lResult = LoadDWORDFromRegistry(L"IsEnhancedKeyboard", &dwValue);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
if (lResult == NO_ERROR)
|
|
|
|
|
Globals.bIsEnhancedKeyboard = (dwValue != 0);
|
|
|
|
|
|
|
|
|
|
/* Sound on click event registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
lResult = LoadDWORDFromRegistry(L"ClickSound", &dwValue);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
if (lResult == NO_ERROR)
|
|
|
|
|
Globals.bSoundClick = (dwValue != 0);
|
|
|
|
|
|
|
|
|
|
/* X coordinate dialog placement registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
lResult = LoadDWORDFromRegistry(L"WindowLeft", &dwValue);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
if (lResult == NO_ERROR)
|
|
|
|
|
Globals.PosX = dwValue;
|
|
|
|
|
|
|
|
|
|
/* Y coordinate dialog placement registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
lResult = LoadDWORDFromRegistry(L"WindowTop", &dwValue);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
if (lResult == NO_ERROR)
|
|
|
|
|
Globals.PosY = dwValue;
|
|
|
|
|
|
|
|
|
|
/* Top window state registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
lResult = LoadDWORDFromRegistry(L"AlwaysOnTop", &dwValue);
|
2019-12-11 23:25:55 +00:00
|
|
|
|
if (lResult == NO_ERROR)
|
|
|
|
|
Globals.bAlwaysOnTop = (dwValue != 0);
|
2021-08-11 19:36:30 +00:00
|
|
|
|
|
|
|
|
|
/* Font information */
|
|
|
|
|
UINT cchCount = _countof(Globals.FontFaceName);
|
|
|
|
|
lResult = LoadStringFromRegistry(L"FontFaceName", Globals.FontFaceName, &cchCount);
|
|
|
|
|
|
|
|
|
|
if (lResult != NO_ERROR) /* Copy default on failure */
|
|
|
|
|
StringCchCopyW(Globals.FontFaceName, _countof(Globals.FontFaceName), L"MS Shell Dlg");
|
|
|
|
|
|
|
|
|
|
lResult = LoadDWORDFromRegistry(L"FontHeight", &dwValue);
|
|
|
|
|
if (lResult == NO_ERROR)
|
|
|
|
|
Globals.FontHeight = dwValue;
|
2019-12-11 23:25:55 +00:00
|
|
|
|
}
|
2019-03-02 17:10:26 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
VOID SaveSettings(VOID)
|
|
|
|
|
{
|
|
|
|
|
WINDOWPLACEMENT wp;
|
2019-03-02 17:10:26 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Initialize the window placement structure */
|
|
|
|
|
wp.length = sizeof(WINDOWPLACEMENT);
|
|
|
|
|
GetWindowPlacement(Globals.hMainWnd, &wp);
|
2019-03-02 17:10:26 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Warning dialog registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
SaveDWORDToRegistry(L"ShowWarning", Globals.bShowWarning);
|
2019-03-02 17:10:26 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Enhanced keyboard switch dialog registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
SaveDWORDToRegistry(L"IsEnhancedKeyboard", Globals.bIsEnhancedKeyboard);
|
2019-03-02 17:10:26 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Sound on click event registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
SaveDWORDToRegistry(L"ClickSound", Globals.bSoundClick);
|
2019-07-15 13:59:06 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* X coordinate dialog placement registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
SaveDWORDToRegistry(L"WindowLeft", wp.rcNormalPosition.left);
|
2019-07-15 13:59:06 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Y coordinate dialog placement registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
SaveDWORDToRegistry(L"WindowTop", wp.rcNormalPosition.top);
|
2019-07-15 13:59:06 +00:00
|
|
|
|
|
2019-12-11 23:25:55 +00:00
|
|
|
|
/* Top window state registry setting */
|
2021-08-11 19:36:30 +00:00
|
|
|
|
SaveDWORDToRegistry(L"AlwaysOnTop", Globals.bAlwaysOnTop);
|
|
|
|
|
|
|
|
|
|
/* Font information */
|
|
|
|
|
SaveStringToRegistry(L"FontFaceName", Globals.FontFaceName, _countof(Globals.FontFaceName));
|
|
|
|
|
SaveDWORDToRegistry(L"FontHeight", Globals.FontHeight);
|
2018-11-17 20:27:33 +00:00
|
|
|
|
}
|