Author: jgardou
Date: Sat Mar  5 16:45:09 2011
New Revision: 50974

URL: http://svn.reactos.org/svn/reactos?rev=50974&view=rev
Log:
[EXPLORER-NEW]
  - Allow displaying seconds in tray upon registry setting
Patch by Edijs Kolesnikovics

Modified:
    trunk/reactos/base/shell/explorer-new/trayntfy.c

Modified: trunk/reactos/base/shell/explorer-new/trayntfy.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer-new/trayntfy.c?rev=50974&r1=50973&r2=50974&view=diff
==============================================================================
--- trunk/reactos/base/shell/explorer-new/trayntfy.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer-new/trayntfy.c [iso-8859-1] Sat Mar  5 
16:45:09 2011
@@ -19,12 +19,15 @@
  */
 
 #include <precomp.h>
+#include <string.h>
 
 /*
  * TrayClockWnd
- */
+ */ 
 
 static const TCHAR szTrayClockWndClass[] = TEXT("TrayClockWClass");
+static LPCTSTR s_szRegistryKey = 
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced");
+BOOL blShowSeconds;
 
 #define ID_TRAYCLOCK_TIMER  0
 #define ID_TRAYCLOCK_TIMER_INIT 1
@@ -34,11 +37,51 @@
     BOOL IsTime;
     DWORD dwFormatFlags;
     LPCTSTR lpFormat;
-} ClockWndFormats[] = {
-    {TRUE, TIME_NOSECONDS, NULL},
-    {FALSE, 0, TEXT("dddd")},
-    {FALSE, DATE_SHORTDATE, NULL},
-};
+}ClockWndFormats[]= {
+{TRUE, 0, NULL},
+{FALSE, 0, TEXT("dddd")},
+{FALSE, DATE_SHORTDATE, NULL}
+};                                      
+
+HRESULT RegGetDWord(HKEY hKey, LPCTSTR szValueName, DWORD * lpdwResult) 
+{
+       LONG lResult;
+       DWORD dwDataSize = sizeof(DWORD);
+       DWORD dwType = 0;
+
+       // Check input parameters...
+       if (hKey == NULL || lpdwResult == NULL) return E_INVALIDARG;
+
+       // Get dword value from the registry...
+       lResult = RegQueryValueEx(hKey, szValueName, 0, &dwType, (LPBYTE) 
lpdwResult, &dwDataSize );
+
+       // Check result and make sure the registry value is a 
DWORD(REG_DWORD)...
+       if (lResult != ERROR_SUCCESS) return HRESULT_FROM_WIN32(lResult);
+       else if (dwType != REG_DWORD) return DISP_E_TYPEMISMATCH;
+
+       return NOERROR;
+}
+
+void LoadSettings(void)
+{
+       HKEY hKey = NULL;
+       DWORD dwValue;
+
+       if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == 
ERROR_SUCCESS)
+       {
+                RegGetDWord(hKey,  TEXT("blShowSeconds"), &dwValue);
+                if (dwValue == 1)
+                {
+                    blShowSeconds = TRUE;
+                }
+                else
+                {
+                    blShowSeconds = FALSE;
+                }
+
+               RegCloseKey(hKey);
+       }
+}
 
 #define CLOCKWND_FORMAT_COUNT (sizeof(ClockWndFormats) / 
sizeof(ClockWndFormats[0]))
 
@@ -52,6 +95,7 @@
     HFONT hFont;
     RECT rcText;
     SYSTEMTIME LocalTime;
+       
     union
     {
         DWORD dwFlags;
@@ -233,6 +277,11 @@
 
         if (iRet != 0 && i == 0)
         {
+                       if (blShowSeconds == FALSE)
+                       {
+                               (This->szLines[0][5] = '\0');
+                       };
+                       
             /* Set the window text to the time only */
             SetWindowText(This->hWnd,
                           This->szLines[i]);
@@ -296,7 +345,10 @@
     /* Calculate the due time */
     GetLocalTime(&This->LocalTime);
     uiDueTime = 1000 - (UINT)This->LocalTime.wMilliseconds;
-    uiDueTime += (59 - (UINT)This->LocalTime.wSecond) * 1000;
+       if (blShowSeconds == TRUE)
+               uiDueTime += ( (UINT)This->LocalTime.wSecond) * 100;
+       else
+               uiDueTime += (59 - (UINT)This->LocalTime.wSecond) * 1000;
 
     if (uiDueTime < USER_TIMER_MINIMUM || uiDueTime > USER_TIMER_MAXIMUM)
         uiDueTime = 1000;
@@ -350,6 +402,7 @@
 {
     UINT uiDueTime;
     BOOL Ret;
+       int intWait1, intWait2;
 
     /* Kill the initialization timer */
     KillTimer(This->hWnd,
@@ -357,15 +410,26 @@
     This->IsInitTimerEnabled = FALSE;
 
     uiDueTime = TrayClockWnd_CalculateDueTime(This);
-
-    if (uiDueTime > (60 * 1000) - 200)
+       
+       if (blShowSeconds == TRUE) 
+       {
+               intWait1 = 1000-200;
+               intWait2 = 1000;
+       }
+       else
+       {
+               intWait1 = 60*1000-200;
+               intWait2 = 60*1000;
+       }
+
+    if (uiDueTime > intWait1)
     {
         /* The update of the clock will be up to 200 ms late, but that's
-           acceptable. We're going to setup a timer that fires every
-           minute. */
+           acceptable. We're going to setup a timer that fires depending
+           intWait2. */   
         Ret = SetTimer(This->hWnd,
                        ID_TRAYCLOCK_TIMER,
-                       60 * 1000,
+                                          intWait2,
                        NULL) != 0;
         This->IsTimerEnabled = Ret;
 
@@ -375,7 +439,7 @@
     else
     {
         /* Recalibrate the timer and recalculate again when the current
-           minute ends. */
+           minute/second ends. */
         TrayClockWnd_ResetTime(This);
     }
 }
@@ -614,6 +678,7 @@
     PTRAY_CLOCK_WND_DATA TcData;
     DWORD dwStyle;
     HWND hWnd = NULL;
+       LoadSettings();
 
     TcData = HeapAlloc(hProcessHeap,
                        0,


Reply via email to