diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index b78ca7a8..ea9882a2 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -4677,19 +4677,7 @@ LRESULT CMeterWindow::OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam) if (pCopyDataStruct && (pCopyDataStruct->dwData == 1) && (pCopyDataStruct->cbData > 0)) { - // Check that we're still alive - bool found = false; - std::map::const_iterator iter = Rainmeter->GetAllMeterWindows().begin(); - for ( ; iter != Rainmeter->GetAllMeterWindows().end(); ++iter) - { - if ((*iter).second == this) - { - found = true; - break; - } - } - - if (found) + if (Rainmeter->HasMeterWindow(this)) { const WCHAR* command = (const WCHAR*)pCopyDataStruct->lpData; Rainmeter->ExecuteCommand(command, this); diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 29c791d5..ed3e3e28 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -1172,7 +1172,10 @@ LRESULT CALLBACK CRainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP break; case WM_RAINMETER_EXECUTE: - Rainmeter->ExecuteCommand((const WCHAR*)lParam, (CMeterWindow*)wParam); + if (Rainmeter->HasMeterWindow((CMeterWindow*)wParam)) + { + Rainmeter->ExecuteCommand((const WCHAR*)lParam, (CMeterWindow*)wParam); + } break; default: @@ -1598,6 +1601,19 @@ void CRainmeter::RemoveUnmanagedMeterWindow(CMeterWindow* meterWindow) } } +bool CRainmeter::HasMeterWindow(const CMeterWindow* meterWindow) const +{ + for (auto it = m_MeterWindows.begin(); it != m_MeterWindows.end(); ++it) + { + if ((*it).second == meterWindow) + { + return true; + } + } + + return false; +} + CMeterWindow* CRainmeter::GetMeterWindow(const std::wstring& folderPath) { const WCHAR* folderSz = folderPath.c_str(); diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 1cf1eb1a..07a45600 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -110,6 +110,8 @@ public: CTrayWindow* GetTrayWindow() { return m_TrayWindow; } + bool HasMeterWindow(const CMeterWindow* meterWindow) const; + CMeterWindow* GetMeterWindow(const std::wstring& folderPath); CMeterWindow* GetMeterWindowByINI(const std::wstring& ini_searching); std::pair GetMeterWindowIndex(const std::wstring& folderPath, const std::wstring& file);