From f15a2f92556a29194e70bac4fdfda66897622f7e Mon Sep 17 00:00:00 2001 From: Ziliang Guo Date: Sun, 14 Dec 2014 05:48:05 +0000 Subject: [PATCH] [CALC] Switch calc to using the registry for storing configuration values. Remove 9x codepath. Patch by Lee Schroeder. Cleaning up Ziliang Guo. CORE-7746 svn path=/trunk/; revision=65633 --- reactos/base/applications/calc/lang/en-US.rc | 12 +- reactos/base/applications/calc/winmain.c | 117 ++++++++++++++----- reactos/boot/bootdata/hivedef.inf | 5 + 3 files changed, 97 insertions(+), 37 deletions(-) diff --git a/reactos/base/applications/calc/lang/en-US.rc b/reactos/base/applications/calc/lang/en-US.rc index b7c04a6dc6d..dc04ceb653f 100644 --- a/reactos/base/applications/calc/lang/en-US.rc +++ b/reactos/base/applications/calc/lang/en-US.rc @@ -330,8 +330,8 @@ BEGIN END POPUP "View" BEGIN - MENUITEM "Standard", IDM_VIEW_STANDARD, CHECKED - MENUITEM "Scientific", IDM_VIEW_SCIENTIFIC, CHECKED + MENUITEM "Standard", IDM_VIEW_STANDARD + MENUITEM "Scientific", IDM_VIEW_SCIENTIFIC MENUITEM "Conversion", IDM_VIEW_CONVERSION MENUITEM SEPARATOR MENUITEM "Hex\tF5", IDM_VIEW_HEX, CHECKED @@ -362,8 +362,8 @@ BEGIN END POPUP "View" BEGIN - MENUITEM "Standard", IDM_VIEW_STANDARD, CHECKED - MENUITEM "Scientific", IDM_VIEW_SCIENTIFIC, CHECKED + MENUITEM "Standard", IDM_VIEW_STANDARD + MENUITEM "Scientific", IDM_VIEW_SCIENTIFIC MENUITEM "Conversion", IDM_VIEW_CONVERSION MENUITEM SEPARATOR MENUITEM "Hex\tF5", IDM_VIEW_HEX, CHECKED @@ -395,8 +395,8 @@ BEGIN END POPUP "View" BEGIN - MENUITEM "Standard", IDM_VIEW_STANDARD, CHECKED - MENUITEM "Scientific", IDM_VIEW_SCIENTIFIC, CHECKED + MENUITEM "Standard", IDM_VIEW_STANDARD + MENUITEM "Scientific", IDM_VIEW_SCIENTIFIC MENUITEM "Conversion", IDM_VIEW_CONVERSION MENUITEM SEPARATOR MENUITEM "Group digits", IDM_VIEW_GROUP, CHECKED diff --git a/reactos/base/applications/calc/winmain.c b/reactos/base/applications/calc/winmain.c index 589a453a6ae..ca72f2ace2c 100644 --- a/reactos/base/applications/calc/winmain.c +++ b/reactos/base/applications/calc/winmain.c @@ -225,38 +225,40 @@ calc_t calc; static void load_config(void) { - TCHAR buf[32]; DWORD tmp; -#if _WIN32_WINNT >= 0x0500 HKEY hKey; -#endif + + /* If no settings are found in the registry, then use the default options */ + calc.layout = CALC_LAYOUT_STANDARD; + calc.usesep = FALSE; - /* Try to load last selected layout */ - GetProfileString(TEXT("SciCalc"), TEXT("layout"), TEXT("0"), buf, SIZEOF(buf)); - if (_stscanf(buf, TEXT("%lu"), &calc.layout) != 1) - calc.layout = CALC_LAYOUT_STANDARD; + /* Get the configuration based on what version of Windows that's being used */ + if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Calc"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) + { + /* Try to load last selected layout */ + tmp = sizeof(calc.layout); + if (RegQueryValueEx(hKey, TEXT("layout"), NULL, NULL, (LPBYTE)&calc.layout, &tmp) != ERROR_SUCCESS) + calc.layout = CALC_LAYOUT_STANDARD; - /* Try to load last selected formatting option */ - GetProfileString(TEXT("SciCalc"), TEXT("UseSep"), TEXT("0"), buf, SIZEOF(buf)); - if (_stscanf(buf, TEXT("%lu"), &tmp) != 1) - calc.usesep = FALSE; - else - calc.usesep = (tmp == 1) ? TRUE : FALSE; + /* Try to load last selected formatting option */ + tmp = sizeof(calc.usesep); + if (RegQueryValueEx(hKey, TEXT("UseSep"), NULL, NULL, (LPBYTE)&calc.usesep, &tmp) != ERROR_SUCCESS) + calc.usesep = FALSE; + + /* close the key */ + RegCloseKey(hKey); + } /* memory is empty at startup */ calc.is_memory = FALSE; -#if _WIN32_WINNT >= 0x0500 /* empty these values */ calc.sDecimal[0] = TEXT('\0'); calc.sThousand[0] = TEXT('\0'); /* try to open the registry */ - if (RegOpenKeyEx(HKEY_CURRENT_USER, - TEXT("Control Panel\\International"), - 0, - KEY_QUERY_VALUE, - &hKey) == ERROR_SUCCESS) { + if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\International"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) + { /* get these values (ignore errors) */ tmp = sizeof(calc.sDecimal); RegQueryValueEx(hKey, TEXT("sDecimal"), NULL, NULL, (LPBYTE)calc.sDecimal, &tmp); @@ -277,20 +279,24 @@ static void load_config(void) /* get the string lengths */ calc.sDecimal_len = _tcslen(calc.sDecimal); calc.sThousand_len = _tcslen(calc.sThousand); -#else - /* acquire regional settings */ - calc.sDecimal_len = GetProfileString(TEXT("intl"), TEXT("sDecimal"), TEXT("."), calc.sDecimal, SIZEOF(calc.sDecimal)); - calc.sThousand_len = GetProfileString(TEXT("intl"), TEXT("sThousand"), TEXT(","), calc.sThousand, SIZEOF(calc.sThousand)); -#endif } static void save_config(void) { - TCHAR buf[32]; + HKEY hKey; + DWORD sepValue; - _stprintf(buf, TEXT("%lu"), calc.layout); - WriteProfileString(TEXT("SciCalc"), TEXT("layout"), buf); - WriteProfileString(TEXT("SciCalc"), TEXT("UseSep"), (calc.usesep==TRUE) ? TEXT("1") : TEXT("0")); + if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Calc"), 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS ) + { + return; + } + + sepValue = (calc.usesep) ? 1 : 0; + + RegSetValueEx(hKey, TEXT("layout"), 0, REG_DWORD, (const BYTE*)&calc.layout, sizeof(calc.layout)); + RegSetValueEx(hKey, TEXT("UseSep"), 0, REG_DWORD, (const BYTE*)&sepValue, sizeof(sepValue)); + + RegCloseKey(hKey); } static LRESULT post_key_press(LPARAM lParam, WORD idc) @@ -657,7 +663,33 @@ static void update_menu(HWND hwnd) HMENU hMenu = GetSubMenu(GetMenu(hwnd), 1); unsigned int x; - for (x=0; x