From 2a030c084cee104826e5cbc1f925277144b1d77e Mon Sep 17 00:00:00 2001 From: spx Date: Tue, 19 Apr 2011 00:02:00 +0000 Subject: [PATCH] Now re-registers Rainmeter icon when Explorer was restarted. --- Library/TrayWindow.cpp | 21 ++++++++++++++++++--- Library/TrayWindow.h | 3 +++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index 748f51bf..cc85b70f 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -34,6 +34,8 @@ #define RAINMETER_MANUALBETA L"http://rainmeter.net/RainCMS/?q=ManualBeta" #define RAINMETER_DOWNLOADS L"http://rainmeter.net/RainCMS/?q=Downloads" +const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(L"TaskbarCreated"); + extern CRainmeter* Rainmeter; using namespace Gdiplus; @@ -46,7 +48,8 @@ CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance), m_TrayColor2(0, 255, 0), m_Bitmap(), m_TrayValues(), - m_TrayPos() + m_TrayPos(), + m_TrayIconEnabled(true) { WNDCLASS wc; @@ -365,8 +368,8 @@ void CTrayWindow::ReadConfig(CConfigParser& parser) LogWithArgs(LOG_ERROR, L"No such TrayMeter: %s", type.c_str()); } - int trayIcon = parser.ReadInt(L"Rainmeter", L"TrayIcon", 1); - if (trayIcon != 0) + m_TrayIconEnabled = 0!=parser.ReadInt(L"Rainmeter", L"TrayIcon", 1); + if (m_TrayIconEnabled) { AddTrayIcon(); @@ -375,6 +378,10 @@ void CTrayWindow::ReadConfig(CConfigParser& parser) SetTimer(m_Window, TRAYTIMER, 1000, NULL); // Update the tray once per sec } } + else + { + RemoveTrayIcon(); + } } @@ -386,6 +393,14 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA { tray=(CTrayWindow*)((LPCREATESTRUCT)lParam)->lpCreateParams; } + else if (uMsg == WM_TASKBARCREATED) + { + if (tray && tray->IsTrayIconEnabled()) + { + tray->RemoveTrayIcon(); + tray->AddTrayIcon(); + } + } switch(uMsg) { diff --git a/Library/TrayWindow.h b/Library/TrayWindow.h index e671acb4..23a01cd6 100644 --- a/Library/TrayWindow.h +++ b/Library/TrayWindow.h @@ -47,6 +47,7 @@ public: void ReadConfig(CConfigParser& parser); HWND GetWindow() { return m_Window; } + bool IsTrayIconEnabled() { return m_TrayIconEnabled; } protected: static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -71,6 +72,8 @@ private: double m_TrayValues[TRAYICON_SIZE]; int m_TrayPos; + + bool m_TrayIconEnabled; }; #endif