Added tray notifications

This commit is contained in:
Brian 2012-05-05 14:43:48 +03:00
parent 72200ade90
commit 2208cf20c0
2 changed files with 63 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include "DialogManage.h" #include "DialogManage.h"
#include "Error.h" #include "Error.h"
#include "RainmeterQuery.h" #include "RainmeterQuery.h"
#include "resource.h"
#include "../Version.h" #include "../Version.h"
#define RAINMETER_OFFICIAL L"http://rainmeter.net/cms/" #define RAINMETER_OFFICIAL L"http://rainmeter.net/cms/"
@ -57,6 +58,7 @@ CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance),
m_Bitmap(), m_Bitmap(),
m_TrayValues(), m_TrayValues(),
m_TrayPos(), m_TrayPos(),
m_Notification(TRAY_NOTIFICATION_NONE),
m_TrayIconEnabled(true) m_TrayIconEnabled(true)
{ {
WNDCLASS wc = {0}; 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); 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) void CTrayWindow::ReadConfig(CConfigParser& parser)
{ {
// Clear old Settings // Clear old Settings
@ -542,6 +574,23 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
{ {
CDialogManage::Open(); 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; break;

View File

@ -48,15 +48,27 @@ public:
HWND GetWindow() { return m_Window; } HWND GetWindow() { return m_Window; }
bool IsTrayIconEnabled() { return m_TrayIconEnabled; } bool IsTrayIconEnabled() { return m_TrayIconEnabled; }
void ShowWelcomeNotification();
void ShowUpdateNotification(const WCHAR* newVersion);
protected: protected:
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
private: private:
enum TRAY_NOTIFICATION
{
TRAY_NOTIFICATION_NONE,
TRAY_NOTIFICATION_WELCOME,
TRAY_NOTIFICATION_UPDATE
};
void AddTrayIcon(); void AddTrayIcon();
void RemoveTrayIcon(); void RemoveTrayIcon();
void ModifyTrayIcon(double value); void ModifyTrayIcon(double value);
HICON CreateTrayIcon(double value); HICON CreateTrayIcon(double value);
void ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, const WCHAR* text);
HICON m_TrayIcon; HICON m_TrayIcon;
HWND m_Window; HWND m_Window;
HINSTANCE m_Instance; HINSTANCE m_Instance;
@ -72,6 +84,8 @@ private:
double m_TrayValues[TRAYICON_SIZE]; double m_TrayValues[TRAYICON_SIZE];
int m_TrayPos; int m_TrayPos;
TRAY_NOTIFICATION m_Notification;
bool m_TrayIconEnabled; bool m_TrayIconEnabled;
}; };