From 8b9e21e38fac2b70b92aa9e698ce9de7a62e6f93 Mon Sep 17 00:00:00 2001 From: spx Date: Tue, 23 Mar 2010 16:15:07 +0000 Subject: [PATCH] Fixed the crash problem when multiple Rainmeter instances are running and "show desktop" occured. --- Library/Rainmeter.cpp | 16 ++++++++++++++++ Library/Rainmeter.h | 1 + Library/System.cpp | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 8a85feae..8ddcf2bb 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -1472,6 +1472,22 @@ CMeterWindow* CRainmeter::GetMeterWindow(const std::wstring& config) return NULL; } + +CMeterWindow* CRainmeter::GetMeterWindow(HWND hwnd) +{ + std::map::iterator iter = m_Meters.begin(); + + for (; iter != m_Meters.end(); iter++) + { + if ((*iter).second->GetWindow() == hwnd) + { + return (*iter).second; + } + } + + return NULL; +} + /* ** Quit ** diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index c1ec1129..6ed849b8 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -112,6 +112,7 @@ public: CTrayWindow* GetTrayWindow() { return m_TrayWindow; }; CMeterWindow* GetMeterWindow(const std::wstring& config); + CMeterWindow* GetMeterWindow(HWND hwnd); std::map& GetAllMeterWindows() { return m_Meters; }; const std::vector& GetAllConfigs() { return m_ConfigStrings; }; const std::vector& GetAllThemes() { return m_Themes; }; diff --git a/Library/System.cpp b/Library/System.cpp index 9bfe5377..2f0aeb8f 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -581,7 +581,8 @@ BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam) if (GetClassName(hwnd, className, 128) > 0 && wcscmp(className, L"RainmeterMeterWindow") == 0 && - (Window = (CMeterWindow*)GetProp(hwnd, L"RAINMETER"))) + Rainmeter && + (Window = Rainmeter->GetMeterWindow(hwnd))) { if (Window->GetWindowZPosition() == ZPOSITION_ONDESKTOP) {