Updated with an improvement to the registry save/restore module.

svn path=/trunk/; revision=3274
This commit is contained in:
Robert Dickenson 2002-07-20 16:35:34 +00:00
parent f4629b5599
commit 51278afbc0
4 changed files with 98 additions and 23 deletions

View file

@ -1,3 +1,6 @@
#include <defines.h>
#include <reactos/resource.h>
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
@ -167,6 +170,7 @@ END
// Accelerator
//
#ifdef _MSC_VER
IDR_ACCELERATOR ACCELERATORS DISCARDABLE
BEGIN
VK_F2, ID_VIEW_DEGREES, VIRTKEY, NOINVERT
@ -177,6 +181,50 @@ BEGIN
VK_F7, ID_VIEW_OCTAL, VIRTKEY, NOINVERT
VK_F8, ID_VIEW_BINARY, VIRTKEY, NOINVERT
END
#endif // _MSC_VER
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD
PRODUCTVERSION RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "Absolutely no warranties whatsoever - Use at your own risk\0"
VALUE "CompanyName", RES_STR_COMPANY_NAME
VALUE "FileDescription", "ReactOS Calculator by Robert Dickenson\0"
VALUE "FileVersion", "1, 0, 0, 1\0"
VALUE "InternalName", "calc\0"
VALUE "LegalCopyright", "Copyright © 2002 Robert Dickenson\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "calc.exe\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", RES_STR_PRODUCT_NAME
VALUE "ProductVersion", RES_STR_PRODUCT_VERSION
VALUE "SpecialBuild", "Non-versioned Development Beta Release\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0xc09, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
@ -187,6 +235,9 @@ END
STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "ReactOS Calculator"
IDS_APP_REG_KEY "\\Calculator"
IDS_APP_REG_PATH RES_STR_ROSAPP_REGISTRY_ROOT
END
#endif // English (Australia) resources

View file

@ -38,7 +38,7 @@ LIBS = -lgdi32 -luser32 -lkernel32 -lcomctl32
all: $(TARGET).exe
$(TARGET).res: $(TARGET).rc
#$(TARGET).res: $(TARGET).rc
$(TARGET).exe: $(OBJS) $(TARGET).coff
$(CC) -Wl,--subsystem,windows -o $(TARGET).exe $(OBJS) $(TARGET).coff $(LIBS)

View file

@ -11,6 +11,10 @@
#define IDR_CALC_SCIENTIFIC 104
#define IDS_APP_TITLE 105
#define IDR_ACCELERATOR 106
#define IDS_APP_REG_KEY 107
#define IDS_APP_REG_PATH 108
#define IDC_BUTTON1 1000
#define IDC_BUTTON2 1001
#define IDC_EDIT1 1002
@ -33,7 +37,7 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 107
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40015
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101

View file

@ -23,12 +23,14 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <tchar.h>
#include <assert.h>
#define ASSERT assert
#include "main.h"
#include "settings.h"
BOOL CheckResult(LONG error)
static BOOL CheckResult(LONG error)
{
if (error != ERROR_SUCCESS) {
PTSTR msg;
@ -43,46 +45,64 @@ BOOL CheckResult(LONG error)
return TRUE;
}
static BOOL CreateRegistryPath(LPTSTR szRegPath, int nMaxLen)
{
LPTSTR pRegPath = szRegPath;
// Initialise registry path string from application PATH and KEY resources
int nLength = LoadString(hInst, IDS_APP_REG_PATH, szRegPath, nMaxLen);
nLength += LoadString(hInst, IDS_APP_REG_KEY, szRegPath + nLength, nMaxLen - nLength);
ASSERT(nLength < (nMaxLen - 1));
szRegPath[nLength] = _T('\\');
// walk the registry path string creating the tree if required
while (pRegPath = _tcschr(pRegPath, _T('\\'))) {
LONG result;
HKEY hKey = NULL;
*pRegPath = _T('\0');
// Open (or create) the key
result = RegCreateKeyEx(HKEY_CURRENT_USER, szRegPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
if (!CheckResult(result)) return FALSE;
RegCloseKey(hKey);
*pRegPath = _T('\\');
pRegPath = pRegPath + 1;
}
szRegPath[nLength] = _T('\0');
return TRUE;
}
void LoadSettings(void)
{
TCHAR szRegPath[MAX_LOADSTRING];
HKEY hKey;
DWORD dwSize;
LONG result;
char szSubKey[] = "Software\\ReactWare\\Calculator";
if (!CreateRegistryPath(szRegPath, MAX_LOADSTRING)) return;
// Open the key
result = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_READ, &hKey);
result = RegOpenKeyEx(HKEY_CURRENT_USER, szRegPath, 0, KEY_READ, &hKey);
if (!CheckResult(result)) return;
// Read the settings
dwSize = sizeof(CALC_TYPES);
result = RegQueryValueEx(hKey, _T("Preferences"), NULL, NULL, (LPBYTE)&CalcType, &dwSize);
if (!CheckResult(result)) goto abort;
abort:
// Close the key
RegCloseKey(hKey);
}
void SaveSettings(void)
{
HKEY hKey;
TCHAR szRegPath[MAX_LOADSTRING];
HKEY hKey = NULL;
LONG result;
char szSubKey1[] = "Software";
char szSubKey2[] = "Software\\ReactWare";
char szSubKey3[] = "Software\\ReactWare\\Calculator";
// Open (or create) the key
hKey = NULL;
result = RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey1, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
if (!CheckResult(result)) return;
RegCloseKey(hKey);
hKey = NULL;
result = RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey2, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
if (!CheckResult(result)) return;
RegCloseKey(hKey);
hKey = NULL;
result = RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
if (!CreateRegistryPath(szRegPath, MAX_LOADSTRING)) return;
// Open the key
result = RegOpenKeyEx(HKEY_CURRENT_USER, szRegPath, 0, KEY_WRITE, &hKey);
if (!CheckResult(result)) return;
// Save the settings