diff --git a/Library/MeasureCalc.cpp b/Library/MeasureCalc.cpp index 739f3573..4c918de6 100644 --- a/Library/MeasureCalc.cpp +++ b/Library/MeasureCalc.cpp @@ -148,20 +148,25 @@ void CMeasureCalc::RandomFormulaReplace() //To implement random numbers the word "Random" in the string //formula is being replaced by the random number value m_Formula = m_FormulaHolder; - std::wstring::size_type loc = m_Formula.find(L"Random"); + std::wstring::size_type loc = 0; - while(loc != std::wstring::npos) + while ((loc = m_Formula.find_first_of(L"Rr", loc)) != std::wstring::npos) { - int range = (m_HighBound - m_LowBound); - srand((unsigned) rand()); - int randNumber = m_LowBound + (range * rand()/(RAND_MAX + 1.0)); + if (wcsnicmp(L"Random", m_Formula.c_str() + loc, 6) == 0) + { + int range = (m_HighBound - m_LowBound); + srand((unsigned) rand()); + int randNumber = m_LowBound + (range * rand()/(RAND_MAX + 1.0)); - std::wstring randomNumberString= (L""); - wchar_t buf[8]; - _itow(randNumber,buf,10); - randomNumberString.append(buf); + WCHAR buffer[32]; + wsprintf(buffer, L"%i", randNumber); - m_Formula.replace(loc, 6, randomNumberString); - loc = m_Formula.find(L"Random"); + m_Formula.replace(loc, 6, buffer); + loc += wcslen(buffer); + } + else + { + ++loc; + } } } \ No newline at end of file diff --git a/Library/MeterLine.cpp b/Library/MeterLine.cpp index da8a802a..8e153b8f 100644 --- a/Library/MeterLine.cpp +++ b/Library/MeterLine.cpp @@ -92,7 +92,6 @@ void CMeterLine::Initialize() */ void CMeterLine::ReadConfig(const WCHAR* section) { - int i; WCHAR tmpName[256]; // Store the current number of lines so we know if the buffer needs to be updated @@ -109,7 +108,7 @@ void CMeterLine::ReadConfig(const WCHAR* section) m_ScaleValues.clear(); m_MeasureNames.clear(); - for (i = 0; i < lineCount; ++i) + for (int i = 0; i < lineCount; ++i) { if (i == 0) { diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index f7560c6d..e0c3ca0c 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -148,6 +148,12 @@ CMeterWindow::~CMeterWindow() { WriteConfig(); + // Kill the timer + KillTimer(m_Window, METERTIMER); + KillTimer(m_Window, MOUSETIMER); + KillTimer(m_Window, FADETIMER); + KillTimer(m_Window, TRANSITIONTIMER); + // Destroy the meters std::list::iterator j = m_Meters.begin(); for( ; j != m_Meters.end(); ++j) @@ -312,9 +318,11 @@ void CMeterWindow::Refresh(bool init, bool all) // First destroy everything // WriteConfig(); //Not clear why this is needed and it messes up resolution changes - KillTimer(m_Window, METERTIMER); // Kill the timer - KillTimer(m_Window, MOUSETIMER); // Kill the timer - KillTimer(m_Window, FADETIMER); // Kill the timer + // Kill the timer + KillTimer(m_Window, METERTIMER); + KillTimer(m_Window, MOUSETIMER); + KillTimer(m_Window, FADETIMER); + KillTimer(m_Window, TRANSITIONTIMER); std::list::iterator i = m_Measures.begin(); for( ; i != m_Measures.end(); ++i) @@ -2157,7 +2165,6 @@ void CMeterWindow::Update(bool nodraw) // Update all measures std::list::const_iterator i = m_Measures.begin(); - for( ; i != m_Measures.end(); ++i) { try @@ -2335,8 +2342,6 @@ LRESULT CMeterWindow::OnTimer(WPARAM wParam, LPARAM lParam) // MoveWindow(x, y); // } //} - - Rainmeter->ClearDeleteLaterList(); } else if(wParam == TRANSITIONTIMER) { diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index f1708145..0063066e 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -1341,7 +1341,6 @@ void CRainmeter::ClearDeleteLaterList() while (!m_DelayDeleteList.empty()) { CMeterWindow* meterWindow = m_DelayDeleteList.front(); - delete meterWindow; // Remove from the delete later list m_DelayDeleteList.remove(meterWindow); @@ -1356,6 +1355,8 @@ void CRainmeter::ClearDeleteLaterList() break; } } + + delete meterWindow; } } @@ -1382,8 +1383,8 @@ bool CRainmeter::DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater) } else if ((*iter).second == meterWindow) { - delete meterWindow; m_Meters.erase(iter); + delete meterWindow; return true; } } diff --git a/Library/System.cpp b/Library/System.cpp index 029987bf..fabf96c7 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -29,13 +29,15 @@ enum TIMER { TIMER_SHOWDESKTOP = 1, TIMER_COMPOSITION = 2, - TIMER_NETSTATS = 3 + TIMER_NETSTATS = 3, + TIMER_DELETELATER = 4 }; enum INTERVAL { INTERVAL_SHOWDESKTOP = 250, INTERVAL_COMPOSITION = 250, - INTERVAL_NETSTATS = 10000 + INTERVAL_NETSTATS = 10000, + INTERVAL_DELETELATER = 1000 }; MULTIMONITOR_INFO CSystem::c_Monitors = { 0 }; @@ -116,6 +118,7 @@ void CSystem::Initialize(HINSTANCE instance) SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_SHOWDESKTOP, NULL); SetTimer(c_Window, TIMER_NETSTATS, INTERVAL_NETSTATS, NULL); + SetTimer(c_Window, TIMER_DELETELATER, INTERVAL_DELETELATER, NULL); } /* @@ -129,6 +132,7 @@ void CSystem::Finalize() KillTimer(c_Window, TIMER_SHOWDESKTOP); KillTimer(c_Window, TIMER_COMPOSITION); KillTimer(c_Window, TIMER_NETSTATS); + KillTimer(c_Window, TIMER_DELETELATER); if (c_WinEventHook) UnhookWinEvent(c_WinEventHook); @@ -896,9 +900,13 @@ LRESULT CALLBACK CSystem::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP // Statistics CMeasureNet::UpdateStats(); - Rainmeter->WriteStats(false); + if (Rainmeter) Rainmeter->WriteStats(false); return 0; + + case TIMER_DELETELATER: + if (Rainmeter) Rainmeter->ClearDeleteLaterList(); + return 0; } break;