[ros-diffs] [cfinck] 29925: Import the new code for showing floating point values with the correct decimal separator from shell32. sysdm.cpl now shows the processor speed and RAM size values with the correct decimal separator based on the current locale.

cfinck at svn.reactos.org cfinck at svn.reactos.org
Sat Oct 27 23:37:32 CEST 2007


Author: cfinck
Date: Sun Oct 28 01:37:32 2007
New Revision: 29925

URL: http://svn.reactos.org/svn/reactos?rev=29925&view=rev
Log:
Import the new code for showing floating point values with the correct decimal separator from shell32.
sysdm.cpl now shows the processor speed and RAM size values with the correct decimal separator based on the current locale.

Modified:
    trunk/reactos/dll/cpl/sysdm/general.c

Modified: trunk/reactos/dll/cpl/sysdm/general.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/sysdm/general.c?rev=29925&r1=29924&r2=29925&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/sysdm/general.c (original)
+++ trunk/reactos/dll/cpl/sysdm/general.c Sun Oct 28 01:37:32 2007
@@ -198,12 +198,32 @@
     return Ret;
 }
 
-static  VOID
+static VOID
+MakeFloatValueString(double* dFloatValue,
+                     LPTSTR szOutput,
+                     LPTSTR szAppend)
+{
+    TCHAR szDecimalSeparator[4];
+
+    // Get the decimal separator for the current locale
+    if( GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szDecimalSeparator, sizeof(szDecimalSeparator) / sizeof(TCHAR)) > 0)
+    {
+        UCHAR uDecimals;
+        UINT uIntegral;
+
+        // Show the value with two decimals
+        uIntegral = (UINT)*dFloatValue;
+        uDecimals = (UCHAR)((UINT)(*dFloatValue * 100) - uIntegral * 100);
+
+        wsprintf(szOutput, _T("%u%s%02u %s"), uIntegral, szDecimalSeparator, uDecimals, szAppend);
+    }
+}
+
+static VOID
 SetProcSpeed(HWND hwnd,
              HKEY hKey,
              LPTSTR Value,
              UINT uID)
-
 {
     TCHAR szBuf[64];
     DWORD BufSize = sizeof(DWORD);
@@ -228,12 +248,12 @@
     {
         if (ppi.CurrentMhz < 1000)
         {
-            _stprintf(szBuf, _T("%lu MHz"), ppi.CurrentMhz);
+            wsprintf(szBuf, _T("%lu MHz"), ppi.CurrentMhz);
         }
         else
         {
             double flt = ppi.CurrentMhz / 1000.0;
-            _stprintf(szBuf, _T("%.2f GHz"), flt);
+            MakeFloatValueString(&flt, szBuf, _T("GHz"));
         }
 
         SetDlgItemText(hwnd,
@@ -289,29 +309,28 @@
     {
         TCHAR szStr[32];
         double dTotalPhys;
-        UINT i = 0;
-        static const UINT uStrId[] = {
-            IDS_MEGABYTE,
-            IDS_GIGABYTE,
-            IDS_TERABYTE,
-            IDS_PETABYTE
-        };
 
         if (MemStat.ullTotalPhys > 1024 * 1024 * 1024)
         {
-            /* We're dealing with GBs or more */
+            UINT i = 0;
+            static const UINT uStrId[] = {
+                IDS_GIGABYTE,
+                IDS_TERABYTE,
+                IDS_PETABYTE
+            };
+
+            // We're dealing with GBs or more
             MemStat.ullTotalPhys /= 1024 * 1024;
-            i++;
 
             if (MemStat.ullTotalPhys > 1024 * 1024)
             {
-                /* We're dealing with TBs or more */
+                // We're dealing with TBs or more
                 MemStat.ullTotalPhys /= 1024;
                 i++;
 
                 if (MemStat.ullTotalPhys > 1024 * 1024)
                 {
-                    /* We're dealing with PBs or more */
+                    // We're dealing with PBs or more
                     MemStat.ullTotalPhys /= 1024;
                     i++;
 
@@ -322,22 +341,18 @@
             }
             else
                 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
+
+            LoadString(hApplet, uStrId[i], szStr, sizeof(szStr) / sizeof(TCHAR));
+            MakeFloatValueString(&dTotalPhys, Buf, szStr);
         }
         else
         {
-            /* We're daling with MBs */
-            dTotalPhys = (double)MemStat.ullTotalPhys / 1024 / 1024;
-        }
-
-        if (LoadString(hApplet, uStrId[i], szStr, sizeof(szStr) / sizeof(szStr[0])))
-        {
-            if( _stprintf(Buf, _T("%.2f %s"), dTotalPhys, szStr) )
-            {
-                SetDlgItemText(hwnd,
-                               CurMachineLine,
-                               Buf);
-            }
-        }
+            // We're dealing with MBs, don't show any decimals
+            LoadString(hApplet, IDS_MEGABYTE, szStr, sizeof(szStr) / sizeof(TCHAR));
+            wsprintf(Buf, _T("%u %s"), (UINT)MemStat.ullTotalPhys / 1024 / 1024, szStr);
+        }
+
+        SetDlgItemText(hwnd, CurMachineLine, Buf);
     }
 }
 




More information about the Ros-diffs mailing list