6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
31 BOOL
CheckResult(LONG error
)
33 if (error
!= ERROR_SUCCESS
) {
35 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
36 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
37 MessageBox(NULL
, msg
, szTitle
, MB_ICONERROR
| MB_OK
);
39 MessageBox(NULL
, _T("Error"), szTitle
, MB_ICONERROR
| MB_OK
);
46 void LoadSettings(void)
51 char szSubKey
[] = "Software\\ReactWare\\Calculator";
54 result
= RegOpenKeyEx(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
);
55 if (!CheckResult(result
)) return;
58 dwSize
= sizeof(CALC_TYPES
);
59 result
= RegQueryValueEx(hKey
, _T("Preferences"), NULL
, NULL
, (LPBYTE
)&CalcType
, &dwSize
);
60 if (!CheckResult(result
)) goto abort
;
67 void SaveSettings(void)
71 char szSubKey1
[] = "Software";
72 char szSubKey2
[] = "Software\\ReactWare";
73 char szSubKey3
[] = "Software\\ReactWare\\Calculator";
75 // Open (or create) the key
77 result
= RegCreateKeyEx(HKEY_CURRENT_USER
, szSubKey1
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
78 if (!CheckResult(result
)) return;
81 result
= RegCreateKeyEx(HKEY_CURRENT_USER
, szSubKey2
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
82 if (!CheckResult(result
)) return;
85 result
= RegCreateKeyEx(HKEY_CURRENT_USER
, szSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
86 if (!CheckResult(result
)) return;
89 result
= RegSetValueEx(hKey
, _T("Preferences"), 0, REG_DWORD
, (LPBYTE
)&CalcType
, sizeof(CALC_TYPES
));
90 if (!CheckResult(result
)) goto abort
;