Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added tray notifications

  • Loading branch information...
commit 2208cf20c0dba0fdaeed07dc502c24a7f8c59c8a 1 parent 72200ad
@brianferguson brianferguson authored
Showing with 63 additions and 0 deletions.
  1. +49 −0 Library/TrayWindow.cpp
  2. +14 −0 Library/TrayWindow.h
View
49 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;
View
14 Library/TrayWindow.h
@@ -48,15 +48,27 @@ class CTrayWindow
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 @@ class CTrayWindow
double m_TrayValues[TRAYICON_SIZE];
int m_TrayPos;
+ TRAY_NOTIFICATION m_Notification;
+
bool m_TrayIconEnabled;
};
Please sign in to comment.
Something went wrong with that request. Please try again.