diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index 4b2a637e..cef89501 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -26,6 +26,7 @@ #include "DialogManage.h" #include "Error.h" #include "RainmeterQuery.h" +#include "resource.h" #include "../Version.h" #define RAINMETER_OFFICIAL L"http://rainmeter.net/cms/" @@ -57,6 +58,7 @@ CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance), m_Bitmap(), m_TrayValues(), m_TrayPos(), + m_Notification(TRAY_NOTIFICATION_NONE), m_TrayIconEnabled(true) { WNDCLASS wc = {0}; @@ -274,6 +276,36 @@ HICON CTrayWindow::CreateTrayIcon(double value) return (HICON)LoadImage(hExe, MAKEINTRESOURCE(IDI_TRAY), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); } +void CTrayWindow::ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text) +{ + if (m_Notification == TRAY_NOTIFICATION_NONE) + { + m_Notification = id; + + NOTIFYICONDATA nid = {sizeof(NOTIFYICONDATA)}; + nid.hWnd = m_Window; + nid.uID = IDI_TRAY; + nid.uFlags = NIF_INFO; + nid.uTimeout = 30000; + nid.dwInfoFlags = NIIF_USER; + nid.hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RAINMETER), IMAGE_ICON, 32, 32, LR_SHARED); + wcsncpy_s(nid.szInfoTitle, title, _TRUNCATE); + wcsncpy_s(nid.szInfo, text, _TRUNCATE); + Shell_NotifyIcon(NIM_MODIFY, &nid); + } +} + +void CTrayWindow::ShowWelcomeNotification() +{ + ShowNotification(TRAY_NOTIFICATION_WELCOME, GetString(ID_STR_WELCOME), GetString(ID_STR_CLICKTOMANAGE)); +} + +void CTrayWindow::ShowUpdateNotification(const WCHAR* newVersion) +{ + std::wstring text = GetFormattedString(ID_STR_CLICKTODOWNLOAD, newVersion); + ShowNotification(TRAY_NOTIFICATION_UPDATE, GetString(ID_STR_UPDATEAVAILABLE), text.c_str()); +} + void CTrayWindow::ReadConfig(CConfigParser& parser) { // Clear old Settings @@ -542,6 +574,23 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA { CDialogManage::Open(); } + else if (uMouseMsg == NIN_BALLOONUSERCLICK) + { + if (tray->m_Notification == TRAY_NOTIFICATION_WELCOME) + { + CDialogManage::Open(); + } + else if (tray->m_Notification == TRAY_NOTIFICATION_UPDATE) + { + RunCommand(NULL, RAINMETER_OFFICIAL, SW_SHOWNORMAL); + } + + tray->m_Notification = TRAY_NOTIFICATION_NONE; + } + else if (uMouseMsg == NIN_BALLOONHIDE || uMouseMsg == NIN_BALLOONTIMEOUT) + { + tray->m_Notification = TRAY_NOTIFICATION_NONE; + } } break; diff --git a/Library/TrayWindow.h b/Library/TrayWindow.h index 0e44d2a7..447d2b9e 100644 --- a/Library/TrayWindow.h +++ b/Library/TrayWindow.h @@ -48,15 +48,27 @@ public: HWND GetWindow() { return m_Window; } bool IsTrayIconEnabled() { return m_TrayIconEnabled; } + void ShowWelcomeNotification(); + void ShowUpdateNotification(const WCHAR* newVersion); + protected: static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); private: + enum TRAY_NOTIFICATION + { + TRAY_NOTIFICATION_NONE, + TRAY_NOTIFICATION_WELCOME, + TRAY_NOTIFICATION_UPDATE + }; + void AddTrayIcon(); void RemoveTrayIcon(); void ModifyTrayIcon(double value); HICON CreateTrayIcon(double value); + void ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text); + HICON m_TrayIcon; HWND m_Window; HINSTANCE m_Instance; @@ -72,6 +84,8 @@ private: double m_TrayValues[TRAYICON_SIZE]; int m_TrayPos; + TRAY_NOTIFICATION m_Notification; + bool m_TrayIconEnabled; };