ReactOS  r76032
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 
16 const TCHAR g_szGeneralRegKey[] = _T("Software\\Microsoft\\CharMap");
18 
19 LONG 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 
45 done:
46  if (lResult != ERROR_SUCCESS)
47  pszBuffer[0] = _T('\0');
48  if (hSubKey)
49  RegCloseKey(hSubKey);
50  return lResult;
51 }
52 
53 extern void LoadSettings(void)
54 {
55  HKEY hKey = NULL;
56  int iItemIndex = -1;
57 
59  {
60  TCHAR szBuffer[MAX_PATH];
61  DWORD dwAdvancedChecked;
62  unsigned long type = REG_DWORD, size = 1024;
63 
64  /* Restore last selected font */
65  if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("Font"), szBuffer, (sizeof(szBuffer)/sizeof(szBuffer[0]))) == ERROR_SUCCESS)
66  {
67  //Get combobox handle
69 
70  //Search for match and return index if match found
71  iItemIndex = ComboBox_FindStringExact(hWnd, -1, szBuffer);
72  if(iItemIndex != CB_ERR)
73  {
74  ComboBox_SetCurSel(hWnd, iItemIndex);
76  }
77  }
78 
79  /* Restore last selected character set */
80  if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("CodePage"), szBuffer, (sizeof(szBuffer)/sizeof(szBuffer[0]))) == ERROR_SUCCESS)
81  {
82  //Get combobox handle
84 
85  iItemIndex = ComboBox_FindStringExact(hWnd, -1, szBuffer);
86  if(iItemIndex != CB_ERR)
87  {
88  ComboBox_SetCurSel(hWnd, iItemIndex);
89  }
90  }
91 
92  RegQueryValueEx(hKey, _T("Advanced"), NULL, &type, (LPBYTE)&dwAdvancedChecked, &size);
93 
94  if(dwAdvancedChecked != FALSE)
96 
97  RegCloseKey(hKey);
98  }
99  else
100  {
101  /* Default font seems to be Arial */
103 
104  iItemIndex = ComboBox_FindStringExact(hWnd, -1, _T("Arial"));
105  if(iItemIndex != CB_ERR)
106  {
107  ComboBox_SetCurSel(hWnd, iItemIndex);
109  }
110  }
111 }
112 
113 extern void SaveSettings(void)
114 {
115  HKEY hKey = NULL;
116 
118  {
119  TCHAR szBuffer[MAX_PATH];
120 
122  ComboBox_GetText(hWnd, szBuffer, MAX_PATH);
123 
124  if(*szBuffer != '\0')
125  RegSetValueEx(hKey, _T("Font"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) MAX_PATH);
126 
128  ComboBox_GetText(hWnd, szBuffer, MAX_PATH);
129 
130  if(*szBuffer != '\0')
131  RegSetValueEx(hKey, _T("CodePage"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) MAX_PATH);
132 
133  RegSetValueEx(hKey, _T("Advanced"), 0, REG_DWORD, (LPBYTE)&Settings.IsAdvancedView, (DWORD) sizeof(DWORD));
134 
135  RegCloseKey(hKey);
136  }
137 }
#define RegQueryValueEx
Definition: winreg.h:524
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define IDC_CHECK_ADVANCED
Definition: resource.h:26
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
unsigned char * LPBYTE
Definition: typedefs.h:52
HWND hWnd
Definition: settings.c:17
HANDLE HWND
Definition: compat.h:13
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define ComboBox_GetText(hwndCtl, lpch, cchMax)
Definition: windowsx.h:33
SSSTARS Settings
Definition: settings.c:33
#define SendDlgItemMessage
Definition: winuser.h:5687
#define IDC_COMBO_CHARSET
Definition: resource.h:21
DWORD DWORD
Definition: winlogon.h:75
CHAR * LPTSTR
Definition: xmlstorage.h:192
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define _T(x)
Definition: tchar.h:1542
#define ComboBox_FindStringExact(hwndCtl, indexStart, lpszFind)
Definition: windowsx.h:22
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
const TCHAR g_szGeneralRegKey[]
Definition: settings.c:16
smooth NULL
Definition: ftsmooth.c:557
#define CB_ERR
Definition: winuser.h:2379
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define MF_CHECKED
Definition: winuser.h:132
char TCHAR
Definition: xmlstorage.h:189
#define BM_CLICK
Definition: winuser.h:1868
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
void SaveSettings(void)
Definition: settings.c:113
HANDLE HKEY
Definition: registry.h:24
#define MAX_PATH
Definition: compat.h:26
#define REG_DWORD
Definition: nt_native.h:1497
#define ComboBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:41
#define IDC_FONTCOMBO
Definition: resource.h:12
VOID ChangeMapFont(HWND hDlg)
Definition: charmap.c:116
LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
Definition: settings.c:19
#define RegOpenKeyEx
Definition: winreg.h:520
GLsizeiptr size
Definition: glext.h:5919
HWND hCharmapDlg
Definition: charmap.c:21
#define RegOpenKey
Definition: winreg.h:519
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
UINT WPARAM LPARAM LRESULT & lResult
Definition: precomp.h:53
void LoadSettings(void)
Definition: settings.c:53
#define REG_SZ
Definition: layer.c:22