ReactOS 0.4.15-dev-8348-gc1b9bb5
settings.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Character Map
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/charmap/settings.c
5 * PURPOSE: save/load settings
6 * COPYRIGHT: Copyright 2012 Edijs Kolesnikovics <terminedijs@yahoo.com>
7 *
8 */
9
10#include "precomp.h"
11
12#include <winreg.h>
13#include <windowsx.h>
14#include <tchar.h>
15
16const TCHAR g_szGeneralRegKey[] = _T("Software\\Microsoft\\CharMap");
18
19LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
20{
21 LONG lResult;
22 HKEY hSubKey = NULL;
23 DWORD cbData, dwType;
24
25 if (lpSubKey)
26 {
27 lResult = RegOpenKey(hKey, lpSubKey, &hSubKey);
28 if (lResult != ERROR_SUCCESS)
29 goto done;
30 hKey = hSubKey;
31 }
32
33 cbData = (dwBufferLen - 1) * sizeof(*pszBuffer);
34 lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, (LPBYTE) pszBuffer, &cbData);
35 if (lResult != ERROR_SUCCESS)
36 goto done;
37 if (dwType != REG_SZ)
38 {
39 lResult = -1;
40 goto done;
41 }
42
43 pszBuffer[cbData / sizeof(*pszBuffer)] = _T('\0');
44
45done:
46 if (lResult != ERROR_SUCCESS)
47 pszBuffer[0] = _T('\0');
48 if (hSubKey)
49 RegCloseKey(hSubKey);
50 return lResult;
51}
52
53extern void LoadSettings(void)
54{
55 HKEY hKey = NULL;
56 int iItemIndex = -1;
57
59 {
60 TCHAR szBuffer[MAX_PATH];
61 DWORD dwAdvancedChecked;
62 DWORD type, size = sizeof(dwAdvancedChecked);
63 LSTATUS lstatus;
64
65 /* Restore last selected font */
66 if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("Font"), szBuffer, (sizeof(szBuffer)/sizeof(szBuffer[0]))) == ERROR_SUCCESS)
67 {
68 //Get combobox handle
70
71 //Search for match and return index if match found
72 iItemIndex = ComboBox_FindStringExact(hWnd, -1, szBuffer);
73 if(iItemIndex != CB_ERR)
74 {
75 ComboBox_SetCurSel(hWnd, iItemIndex);
77 }
78 }
79
80 /* Restore last selected character set */
81 if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("CodePage"), szBuffer, (sizeof(szBuffer)/sizeof(szBuffer[0]))) == ERROR_SUCCESS)
82 {
83 //Get combobox handle
85
86 iItemIndex = ComboBox_FindStringExact(hWnd, -1, szBuffer);
87 if(iItemIndex != CB_ERR)
88 {
89 ComboBox_SetCurSel(hWnd, iItemIndex);
90 }
91 }
92
93 lstatus = RegQueryValueEx(hKey, _T("Advanced"), NULL, &type, (LPBYTE)&dwAdvancedChecked, &size);
94 if (lstatus == ERROR_SUCCESS && type == REG_DWORD && dwAdvancedChecked != FALSE)
95 {
97 }
98
100 }
101 else
102 {
103 /* Default font seems to be Arial */
105
106 iItemIndex = ComboBox_FindStringExact(hWnd, -1, _T("Arial"));
107 if(iItemIndex != CB_ERR)
108 {
109 ComboBox_SetCurSel(hWnd, iItemIndex);
111 }
112 }
113}
114
115extern void SaveSettings(void)
116{
117 HKEY hKey = NULL;
118
120 {
121 TCHAR szBuffer[MAX_PATH];
122
124 ComboBox_GetText(hWnd, szBuffer, MAX_PATH);
125
126 if(*szBuffer != '\0')
127 RegSetValueEx(hKey, _T("Font"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) MAX_PATH);
128
130 ComboBox_GetText(hWnd, szBuffer, MAX_PATH);
131
132 if(*szBuffer != '\0')
133 RegSetValueEx(hKey, _T("CodePage"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) MAX_PATH);
134
135 RegSetValueEx(hKey, _T("Advanced"), 0, REG_DWORD, (LPBYTE)&Settings.IsAdvancedView, (DWORD) sizeof(DWORD));
136
138 }
139}
#define IDC_FONTCOMBO
Definition: resource.h:12
#define IDC_CHECK_ADVANCED
Definition: resource.h:26
#define IDC_COMBO_CHARSET
Definition: resource.h:21
LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
Definition: settings.c:19
void SaveSettings(void)
Definition: settings.c:115
const TCHAR g_szGeneralRegKey[]
Definition: settings.c:16
void LoadSettings(void)
Definition: settings.c:53
HWND hWnd
Definition: settings.c:17
#define RegCloseKey(hKey)
Definition: registry.h:49
HWND hCharmapDlg
Definition: charmap.c:21
VOID ChangeMapFont(HWND hDlg)
Definition: charmap.c:161
#define ERROR_SUCCESS
Definition: deptool.c:10
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
#define REG_SZ
Definition: layer.c:22
#define KEY_READ
Definition: nt_native.h:1023
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_SET_VALUE
Definition: nt_native.h:1017
long LONG
Definition: pedump.c:60
#define REG_DWORD
Definition: sdbapi.c:596
unsigned char * LPBYTE
Definition: typedefs.h:53
#define _T(x)
Definition: vfdio.h:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2595
#define ComboBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:66
#define ComboBox_GetText(hwndCtl, lpch, cchMax)
Definition: windowsx.h:58
#define ComboBox_FindStringExact(hwndCtl, indexStart, lpszFind)
Definition: windowsx.h:47
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define RegQueryValueEx
Definition: winreg.h:524
#define RegOpenKey
Definition: winreg.h:519
#define CB_ERR
Definition: winuser.h:2435
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define BM_CLICK
Definition: winuser.h:1917
#define SendDlgItemMessage
Definition: winuser.h:5851
char TCHAR
Definition: xmlstorage.h:189
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192