mirror of
https://github.com/reactos/reactos.git
synced 2024-09-29 05:54:05 +00:00
[EXPLORER-NEW]
- Allow displaying seconds in tray upon registry setting Patch by Edijs Kolesnikovics svn path=/trunk/; revision=50974
This commit is contained in:
parent
43f10841e0
commit
545fca44dc
|
@ -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 @@ static const struct
|
|||
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 @@ typedef struct _TRAY_CLOCK_WND_DATA
|
|||
HFONT hFont;
|
||||
RECT rcText;
|
||||
SYSTEMTIME LocalTime;
|
||||
|
||||
union
|
||||
{
|
||||
DWORD dwFlags;
|
||||
|
@ -233,6 +277,11 @@ TrayClockWnd_UpdateWnd(IN OUT PTRAY_CLOCK_WND_DATA This)
|
|||
|
||||
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 @@ TrayClockWnd_CalculateDueTime(IN OUT PTRAY_CLOCK_WND_DATA This)
|
|||
/* 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 @@ TrayClockWnd_CalibrateTimer(IN OUT PTRAY_CLOCK_WND_DATA This)
|
|||
{
|
||||
UINT uiDueTime;
|
||||
BOOL Ret;
|
||||
int intWait1, intWait2;
|
||||
|
||||
/* Kill the initialization timer */
|
||||
KillTimer(This->hWnd,
|
||||
|
@ -357,15 +410,26 @@ TrayClockWnd_CalibrateTimer(IN OUT PTRAY_CLOCK_WND_DATA This)
|
|||
This->IsInitTimerEnabled = FALSE;
|
||||
|
||||
uiDueTime = TrayClockWnd_CalculateDueTime(This);
|
||||
|
||||
if (blShowSeconds == TRUE)
|
||||
{
|
||||
intWait1 = 1000-200;
|
||||
intWait2 = 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
intWait1 = 60*1000-200;
|
||||
intWait2 = 60*1000;
|
||||
}
|
||||
|
||||
if (uiDueTime > (60 * 1000) - 200)
|
||||
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 @@ TrayClockWnd_CalibrateTimer(IN OUT PTRAY_CLOCK_WND_DATA This)
|
|||
else
|
||||
{
|
||||
/* Recalibrate the timer and recalculate again when the current
|
||||
minute ends. */
|
||||
minute/second ends. */
|
||||
TrayClockWnd_ResetTime(This);
|
||||
}
|
||||
}
|
||||
|
@ -614,6 +678,7 @@ CreateTrayClockWnd(IN HWND hWndParent,
|
|||
PTRAY_CLOCK_WND_DATA TcData;
|
||||
DWORD dwStyle;
|
||||
HWND hWnd = NULL;
|
||||
LoadSettings();
|
||||
|
||||
TcData = HeapAlloc(hProcessHeap,
|
||||
0,
|
||||
|
|
Loading…
Reference in a new issue