mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +00:00
Added save and restore of calculator mode using registry.
svn path=/trunk/; revision=3240
This commit is contained in:
parent
8e12d121dc
commit
74571d0428
6 changed files with 178 additions and 13 deletions
|
@ -15,7 +15,6 @@
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
#undef APSTUDIO_READONLY_SYMBOLS
|
#undef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// English (Australia) resources
|
// English (Australia) resources
|
||||||
|
|
||||||
|
@ -64,13 +63,22 @@ BEGIN
|
||||||
MENUITEM "S&tandard", ID_VIEW_STANDARD
|
MENUITEM "S&tandard", ID_VIEW_STANDARD
|
||||||
MENUITEM "&Scientific", ID_VIEW_SCIENTIFIC, CHECKED
|
MENUITEM "&Scientific", ID_VIEW_SCIENTIFIC, CHECKED
|
||||||
MENUITEM SEPARATOR
|
MENUITEM SEPARATOR
|
||||||
|
MENUITEM "&Hex\tF5", ID_VIEW_HEX
|
||||||
|
MENUITEM "&Decimal\tF6", ID_VIEW_DECIMAL
|
||||||
|
MENUITEM "&Octal\tF7", ID_VIEW_OCTAL
|
||||||
|
MENUITEM "&Binary\tF8", ID_VIEW_BINARY
|
||||||
|
MENUITEM SEPARATOR
|
||||||
|
MENUITEM "D&egrees\tF2", ID_VIEW_DEGREES
|
||||||
|
MENUITEM "&Radians\tF3", ID_VIEW_RADIANS
|
||||||
|
MENUITEM "&Grads\tF4", ID_VIEW_GRADS
|
||||||
|
MENUITEM SEPARATOR
|
||||||
MENUITEM "D&igit grouping", ID_VIEW_DIGIT_GROUPING
|
MENUITEM "D&igit grouping", ID_VIEW_DIGIT_GROUPING
|
||||||
END
|
END
|
||||||
POPUP "&Help"
|
POPUP "&Help"
|
||||||
BEGIN
|
BEGIN
|
||||||
MENUITEM "&Help Topics", ID_HELP_TOPICS
|
MENUITEM "&Help Topics", ID_HELP_TOPICS
|
||||||
MENUITEM SEPARATOR
|
MENUITEM SEPARATOR
|
||||||
MENUITEM "&About Calculator", ID_HELP_ABOUT
|
MENUITEM "&About Scientific Calculator", ID_HELP_ABOUT
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
|
|
||||||
|
@ -92,6 +100,12 @@ BEGIN
|
||||||
"\0"
|
"\0"
|
||||||
END
|
END
|
||||||
|
|
||||||
|
3 TEXTINCLUDE DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
"\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
#endif // APSTUDIO_INVOKED
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,7 +130,7 @@ END
|
||||||
|
|
||||||
IDD_SCIENTIFIC DIALOG DISCARDABLE 0, 0, 325, 156
|
IDD_SCIENTIFIC DIALOG DISCARDABLE 0, 0, 325, 156
|
||||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
CAPTION "ReactOS Calculator"
|
CAPTION "ReactOS Scientific Calculator"
|
||||||
MENU IDR_CALC_SCIENTIFIC
|
MENU IDR_CALC_SCIENTIFIC
|
||||||
FONT 8, "MS Sans Serif"
|
FONT 8, "MS Sans Serif"
|
||||||
BEGIN
|
BEGIN
|
||||||
|
@ -147,6 +161,34 @@ BEGIN
|
||||||
END
|
END
|
||||||
#endif // APSTUDIO_INVOKED
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Accelerator
|
||||||
|
//
|
||||||
|
|
||||||
|
IDR_ACCELERATOR ACCELERATORS DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
VK_F2, ID_VIEW_DEGREES, VIRTKEY, NOINVERT
|
||||||
|
VK_F3, ID_VIEW_RADIANS, VIRTKEY, NOINVERT
|
||||||
|
VK_F4, ID_VIEW_GRADS, VIRTKEY, NOINVERT
|
||||||
|
VK_F5, ID_VIEW_HEX, VIRTKEY, NOINVERT
|
||||||
|
VK_F6, ID_VIEW_DECIMAL, VIRTKEY, NOINVERT
|
||||||
|
VK_F7, ID_VIEW_OCTAL, VIRTKEY, NOINVERT
|
||||||
|
VK_F8, ID_VIEW_BINARY, VIRTKEY, NOINVERT
|
||||||
|
END
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// String Table
|
||||||
|
//
|
||||||
|
|
||||||
|
STRINGTABLE DISCARDABLE
|
||||||
|
BEGIN
|
||||||
|
IDS_APP_TITLE "ReactOS Calculator"
|
||||||
|
END
|
||||||
|
|
||||||
#endif // English (Australia) resources
|
#endif // English (Australia) resources
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,9 @@
|
||||||
// Global Variables:
|
// Global Variables:
|
||||||
HINSTANCE hInst;
|
HINSTANCE hInst;
|
||||||
HWND hDlgWnd;
|
HWND hDlgWnd;
|
||||||
|
TCHAR szTitle[MAX_LOADSTRING];
|
||||||
CALC_TYPES CalcType;
|
CALC_TYPES CalcType;
|
||||||
|
HACCEL hAccel;
|
||||||
|
|
||||||
BOOL bDigitGrouping = FALSE;
|
BOOL bDigitGrouping = FALSE;
|
||||||
|
|
||||||
|
@ -95,6 +97,34 @@ void OnViewDigitGrouping(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnViewHex(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnViewDecimal(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnViewOctal(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnViewBinary(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnViewDegrees(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnViewRadians(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnViewGrads(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void OnHelpTopics(void)
|
void OnHelpTopics(void)
|
||||||
{
|
{
|
||||||
WinHelp(hDlgWnd, _T("calc"), HELP_CONTENTS, 0);
|
WinHelp(hDlgWnd, _T("calc"), HELP_CONTENTS, 0);
|
||||||
|
@ -137,11 +167,32 @@ LRESULT CALLBACK CalcWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar
|
||||||
CMD_MAP_ENTRY(ID_VIEW_STANDARD, OnViewStandard)
|
CMD_MAP_ENTRY(ID_VIEW_STANDARD, OnViewStandard)
|
||||||
CMD_MAP_ENTRY(ID_VIEW_SCIENTIFIC, OnViewScientific)
|
CMD_MAP_ENTRY(ID_VIEW_SCIENTIFIC, OnViewScientific)
|
||||||
CMD_MAP_ENTRY(ID_VIEW_DIGIT_GROUPING, OnViewDigitGrouping)
|
CMD_MAP_ENTRY(ID_VIEW_DIGIT_GROUPING, OnViewDigitGrouping)
|
||||||
|
CMD_MAP_ENTRY(ID_VIEW_HEX, OnViewHex)
|
||||||
|
CMD_MAP_ENTRY(ID_VIEW_DECIMAL, OnViewDecimal)
|
||||||
|
CMD_MAP_ENTRY(ID_VIEW_OCTAL, OnViewOctal)
|
||||||
|
CMD_MAP_ENTRY(ID_VIEW_BINARY, OnViewBinary)
|
||||||
|
CMD_MAP_ENTRY(ID_VIEW_DEGREES, OnViewDegrees)
|
||||||
|
CMD_MAP_ENTRY(ID_VIEW_RADIANS, OnViewRadians)
|
||||||
|
CMD_MAP_ENTRY(ID_VIEW_GRADS, OnViewGrads)
|
||||||
CMD_MAP_ENTRY(ID_HELP_TOPICS, OnHelpTopics)
|
CMD_MAP_ENTRY(ID_HELP_TOPICS, OnHelpTopics)
|
||||||
CMD_MAP_ENTRY(ID_HELP_ABOUT, OnHelpAbout)
|
CMD_MAP_ENTRY(ID_HELP_ABOUT, OnHelpAbout)
|
||||||
END_CMD_MAP(0)
|
END_CMD_MAP(0)
|
||||||
break;
|
break;
|
||||||
|
/*
|
||||||
|
case WM_KEYUP:
|
||||||
|
case WM_KEYDOWN:
|
||||||
|
{
|
||||||
|
MSG msg;
|
||||||
|
msg.hwnd = hDlg;
|
||||||
|
msg.message = message;
|
||||||
|
msg.wParam = wParam;
|
||||||
|
msg.lParam = lParam;
|
||||||
|
// msg.time;
|
||||||
|
// msg.pt;
|
||||||
|
if (TranslateAccelerator(hDlg, hAccel, &msg)) return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
*/
|
||||||
case WM_NOTIFY:
|
case WM_NOTIFY:
|
||||||
{
|
{
|
||||||
int idctrl;
|
int idctrl;
|
||||||
|
@ -175,10 +226,13 @@ int APIENTRY WinMain(HINSTANCE hInstance,
|
||||||
|
|
||||||
// Initialize global variables
|
// Initialize global variables
|
||||||
hInst = hInstance;
|
hInst = hInstance;
|
||||||
|
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
||||||
|
|
||||||
// Load our settings from the registry
|
// Load our settings from the registry
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
|
|
||||||
|
hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDR_ACCELERATOR);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
CurrentCalcType = CalcType;
|
CurrentCalcType = CalcType;
|
||||||
switch (CalcType) {
|
switch (CalcType) {
|
||||||
|
|
|
@ -35,10 +35,13 @@ extern "C" {
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_LOADSTRING 100
|
||||||
|
|
||||||
typedef enum _CALC_TYPES { STANDARD, SCIENTIFIC, HP42S, OTHER } CALC_TYPES;
|
typedef enum _CALC_TYPES { STANDARD, SCIENTIFIC, HP42S, OTHER } CALC_TYPES;
|
||||||
|
|
||||||
extern HINSTANCE hInst;
|
extern HINSTANCE hInst;
|
||||||
extern HWND hDlgWnd;
|
extern HWND hDlgWnd;
|
||||||
|
extern TCHAR szTitle[];
|
||||||
extern CALC_TYPES CalcType;
|
extern CALC_TYPES CalcType;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,25 +9,32 @@
|
||||||
#define IDD_SCIENTIFIC 102
|
#define IDD_SCIENTIFIC 102
|
||||||
#define IDR_CALC_STANDARD 103
|
#define IDR_CALC_STANDARD 103
|
||||||
#define IDR_CALC_SCIENTIFIC 104
|
#define IDR_CALC_SCIENTIFIC 104
|
||||||
|
#define IDS_APP_TITLE 105
|
||||||
|
#define IDR_ACCELERATOR 106
|
||||||
#define IDC_BUTTON1 1000
|
#define IDC_BUTTON1 1000
|
||||||
#define IDC_BUTTON2 1001
|
#define IDC_BUTTON2 1001
|
||||||
#define IDC_EDIT1 1002
|
#define IDC_EDIT1 1002
|
||||||
//#define ID_EDIT_COPY 40001
|
|
||||||
//#define ID_EDIT_PASTE 40002
|
|
||||||
#define ID_EDIT_COPY 0xE122
|
|
||||||
#define ID_EDIT_PASTE 0xE125
|
|
||||||
#define ID_VIEW_STANDARD 40003
|
#define ID_VIEW_STANDARD 40003
|
||||||
#define ID_VIEW_SCIENTIFIC 40004
|
#define ID_VIEW_SCIENTIFIC 40004
|
||||||
#define ID_VIEW_DIGIT_GROUPING 40005
|
#define ID_VIEW_DIGIT_GROUPING 40005
|
||||||
#define ID_HELP_TOPICS 40006
|
#define ID_VIEW_HEX 40006
|
||||||
#define ID_HELP_ABOUT 40007
|
#define ID_VIEW_DECIMAL 40007
|
||||||
|
#define ID_VIEW_OCTAL 40008
|
||||||
|
#define ID_VIEW_BINARY 40009
|
||||||
|
#define ID_VIEW_DEGREES 40010
|
||||||
|
#define ID_VIEW_RADIANS 40011
|
||||||
|
#define ID_VIEW_GRADS 40012
|
||||||
|
#define ID_HELP_TOPICS 40013
|
||||||
|
#define ID_HELP_ABOUT 40014
|
||||||
|
#define ID_EDIT_COPY 0xE122
|
||||||
|
#define ID_EDIT_PASTE 0xE125
|
||||||
|
|
||||||
// Next default values for new objects
|
// Next default values for new objects
|
||||||
//
|
//
|
||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 103
|
#define _APS_NEXT_RESOURCE_VALUE 107
|
||||||
#define _APS_NEXT_COMMAND_VALUE 40008
|
#define _APS_NEXT_COMMAND_VALUE 40015
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1003
|
#define _APS_NEXT_CONTROL_VALUE 1003
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,16 +22,74 @@
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
|
||||||
|
BOOL CheckResult(LONG error)
|
||||||
|
{
|
||||||
|
if (error != ERROR_SUCCESS) {
|
||||||
|
PTSTR msg;
|
||||||
|
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
|
0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
|
||||||
|
MessageBox(NULL, msg, szTitle, MB_ICONERROR | MB_OK);
|
||||||
|
else
|
||||||
|
MessageBox(NULL, _T("Error"), szTitle, MB_ICONERROR | MB_OK);
|
||||||
|
LocalFree(msg);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
void LoadSettings(void)
|
void LoadSettings(void)
|
||||||
{
|
{
|
||||||
|
HKEY hKey;
|
||||||
|
DWORD dwSize;
|
||||||
|
LONG result;
|
||||||
|
char szSubKey[] = "Software\\ReactWare\\Calculator";
|
||||||
|
|
||||||
|
// Open the key
|
||||||
|
result = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 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)
|
void SaveSettings(void)
|
||||||
{
|
{
|
||||||
}
|
HKEY hKey;
|
||||||
|
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 (!CheckResult(result)) return;
|
||||||
|
|
||||||
|
// Save the settings
|
||||||
|
result = RegSetValueEx(hKey, _T("Preferences"), 0, REG_DWORD, (LPBYTE)&CalcType, sizeof(CALC_TYPES));
|
||||||
|
if (!CheckResult(result)) goto abort;
|
||||||
|
|
||||||
|
abort:
|
||||||
|
// Close the key
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ extern "C" {
|
||||||
#endif // _MSC_VER > 1000
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
|
|
||||||
|
BOOL CheckResult(LONG error);
|
||||||
void LoadSettings(void);
|
void LoadSettings(void);
|
||||||
void SaveSettings(void);
|
void SaveSettings(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue