diff --git a/Library/Litestep.cpp b/Library/Litestep.cpp index 72bae8a1..23827fa6 100644 --- a/Library/Litestep.cpp +++ b/Library/Litestep.cpp @@ -505,15 +505,11 @@ BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage) logInfo.message = pszMessage; // Add timestamp - static DWORD startTime = 0; + static ULONGLONG startTime = CSystem::GetTickCount64(); + ULONGLONG time = CSystem::GetTickCount64(); - DWORD time = GetTickCount(); - if (startTime == 0) - { - startTime = time; - } WCHAR buffer[128]; - _snwprintf_s(buffer, _TRUNCATE, L"(%02i:%02i:%02i.%03i) ", (time - startTime) / (1000 * 60* 60), ((time - startTime) / (1000 * 60)) % 60, ((time - startTime) / 1000) % 60, (time - startTime) % 1000); + _snwprintf_s(buffer, _TRUNCATE, L"(%02llu:%02llu:%02llu.%03llu) ", (time - startTime) / (1000 * 60* 60), ((time - startTime) / (1000 * 60)) % 60, ((time - startTime) / 1000) % 60, (time - startTime) % 1000); std::wstring message(buffer); logInfo.timestamp = message; diff --git a/Library/MeasureUptime.cpp b/Library/MeasureUptime.cpp index 7ebd3471..fde30e82 100644 --- a/Library/MeasureUptime.cpp +++ b/Library/MeasureUptime.cpp @@ -19,6 +19,7 @@ #include "StdAfx.h" #include "MeasureUptime.h" #include "Rainmeter.h" +#include "System.h" /* ** CMeasureUptime @@ -73,8 +74,8 @@ bool CMeasureUptime::Update() { if (!CMeasure::PreUpdate()) return false; - DWORD ticks = GetTickCount(); - m_Value = ticks / 1000; + ULONGLONG ticks = CSystem::GetTickCount64(); + m_Value = (double)(__int64)(ticks / 1000); return PostUpdate(); } diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 4eeed9b7..54756e34 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -803,7 +803,6 @@ bool CMeter::Draw(Graphics& graphics) if (m_AntiAlias) { - //graphics.SetInterpolationMode(InterpolationModeBicubic); // Bicubic is not suitable for shrinking an image. graphics.SetSmoothingMode(SmoothingModeHighQuality); graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality); } diff --git a/Library/MeterBitmap.cpp b/Library/MeterBitmap.cpp index c42fb2c3..9708cad1 100644 --- a/Library/MeterBitmap.cpp +++ b/Library/MeterBitmap.cpp @@ -21,6 +21,7 @@ #include "Measure.h" #include "Error.h" #include "Rainmeter.h" +#include "System.h" using namespace Gdiplus; @@ -252,7 +253,7 @@ bool CMeterBitmap::Update() if ((int)(value * realFrames) != (int)(m_Value * realFrames)) { m_TransitionStartValue = m_Value; - m_TransitionStartTicks = GetTickCount(); + m_TransitionStartTicks = CSystem::GetTickCount64(); } else { @@ -301,7 +302,6 @@ bool CMeterBitmap::Draw(Graphics& graphics) int x = GetX(); int y = GetY(); - DWORD diffTicks = GetTickCount() - m_TransitionStartTicks; if (m_Extend) { int value = (int)m_Value; @@ -362,20 +362,21 @@ bool CMeterBitmap::Draw(Graphics& graphics) // If transition is ongoing the pick the correct frame if (m_TransitionStartTicks > 0) { - int range = ((value % realFrames) - ((int)transitionValue % realFrames)) * (m_TransitionFrameCount + 1); + int diffTicks = (int)(CSystem::GetTickCount64() - m_TransitionStartTicks); + + int range = ((value % realFrames) - (transitionValue % realFrames)) * (m_TransitionFrameCount + 1); if (range < 0) { range += m_FrameCount; } - int frameAdjustment = 0; - frameAdjustment = range * diffTicks / ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate()); + int frameAdjustment = range * diffTicks / ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate()); if (frameAdjustment > range) { m_TransitionStartTicks = 0; // The transition is over. Draw with the real value. } else { - frame = ((int)transitionValue % realFrames) * (m_TransitionFrameCount + 1); + frame = (transitionValue % realFrames) * (m_TransitionFrameCount + 1); frame += frameAdjustment; frame %= m_FrameCount; } @@ -430,7 +431,9 @@ bool CMeterBitmap::Draw(Graphics& graphics) // If transition is ongoing the pick the correct frame if (m_TransitionStartTicks > 0) { - if ((int)diffTicks > ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate())) + int diffTicks = (int)(CSystem::GetTickCount64() - m_TransitionStartTicks); + + if (diffTicks > ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate())) { m_TransitionStartTicks = 0; // The transition is over. Draw with the real value. } diff --git a/Library/MeterBitmap.h b/Library/MeterBitmap.h index 2541514f..22c7f7f1 100644 --- a/Library/MeterBitmap.h +++ b/Library/MeterBitmap.h @@ -50,7 +50,7 @@ private: int m_Digits; double m_Value; - DWORD m_TransitionStartTicks; + ULONGLONG m_TransitionStartTicks; double m_TransitionStartValue; }; diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 08572bd7..27826b38 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -3050,13 +3050,13 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam) } else if (wParam == FADETIMER) { - DWORD ticks = GetTickCount(); + ULONGLONG ticks = CSystem::GetTickCount64(); if (m_FadeStartTime == 0) { m_FadeStartTime = ticks; } - if (ticks - m_FadeStartTime > (DWORD)m_FadeDuration) + if (ticks - m_FadeStartTime > (ULONGLONG)m_FadeDuration) { KillTimer(m_Window, FADETIMER); m_FadeStartTime = 0; @@ -3071,7 +3071,7 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam) } else { - double value = (ticks - m_FadeStartTime); + double value = (double)(__int64)(ticks - m_FadeStartTime); value /= m_FadeDuration; value *= m_FadeEndValue - m_FadeStartValue; value += m_FadeStartValue; diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index de6062c5..73077e51 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -409,7 +409,7 @@ private: BLURMODE m_BlurMode; // The blur mode HRGN m_BlurRegion; // Handle to the blur region - DWORD m_FadeStartTime; + ULONGLONG m_FadeStartTime; int m_FadeStartValue; int m_FadeEndValue; int m_TransparencyValue; diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index a9f852f3..e68ebd0c 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -3728,11 +3728,13 @@ void CRainmeter::ReadStats() */ void CRainmeter::WriteStats(bool bForce) { - static DWORD lastWrite = 0; + static ULONGLONG lastWrite = 0; - if (bForce || (lastWrite + 1000 * 60 < GetTickCount())) + ULONGLONG ticks = CSystem::GetTickCount64(); + + if (bForce || (lastWrite + 1000 * 60 < ticks)) { - lastWrite = GetTickCount(); + lastWrite = ticks; // Write the date for statistics WritePrivateProfileString(L"Statistics", L"Since", m_StatsDate.c_str(), m_StatsFile.c_str()); diff --git a/Library/System.cpp b/Library/System.cpp index 412e0ef0..a6bb6b3d 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -951,6 +951,32 @@ OSPLATFORM CSystem::GetOSPlatform() return c_Platform; } +/* +** GetTickCount64 +** +** Retrieves the number of milliseconds that have elapsed since the system was started. +** In XP, returns the predictive value due to the 32bit limitation. +** +*/ +ULONGLONG CSystem::GetTickCount64() +{ + typedef ULONGLONG (WINAPI * FPGETTICKCOUNT64)(); + static FPGETTICKCOUNT64 c_GetTickCount64 = (FPGETTICKCOUNT64)GetProcAddress(GetModuleHandle(L"kernel32"), "GetTickCount64"); + + if (c_GetTickCount64) + { + return c_GetTickCount64(); + } + else + { + static ULONGLONG lastTicks = 0; + ULONGLONG ticks = GetTickCount(); + while (ticks < lastTicks) ticks += 0x100000000; + lastTicks = ticks; + return ticks; + } +} + /* ** RmLoadLibrary ** diff --git a/Library/System.h b/Library/System.h index 6ed36cc6..0892d916 100644 --- a/Library/System.h +++ b/Library/System.h @@ -72,6 +72,7 @@ public: static void PrepareHelperWindow(HWND WorkerW); static OSPLATFORM GetOSPlatform(); + static ULONGLONG GetTickCount64(); static HMODULE RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError = NULL, bool ignoreErrors = false); static void ResetWorkingDirectory();