-
Notifications
You must be signed in to change notification settings - Fork 0
/
TRAY_HANDLER.cpp
69 lines (57 loc) · 2.37 KB
/
TRAY_HANDLER.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "TRAY_HANDLER.h"
#include "LANGUAGE_MANAGER.h"
BOOL TRAY_HANDLER::CreateTrayIcon(HWND hwnd, UINT uID, LONG iconID, UINT uCallbackMessage, WORD messageID)
{
HICON tray_icon=NULL;
LoadIconMetric((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), MAKEINTRESOURCE(iconID), LIM_SMALL, &tray_icon);
if (!tray_icon) return FALSE;
NOTIFYICONDATA notification;
notification.cbSize = sizeof(NOTIFYICONDATA);//TODO(fran): this is not quite the way
notification.hWnd = hwnd;
notification.uID = uID;
notification.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_SHOWTIP;//TODO(fran): check this
notification.uCallbackMessage = uCallbackMessage;
notification.hIcon = tray_icon;
notification.dwState = NIS_SHAREDICON;//TODO(fran): check this
notification.dwStateMask = NIS_SHAREDICON;
notification.szInfo[0] = 0;
notification.uVersion = NOTIFYICON_VERSION_4;//INFO(fran): this changes the message format, but not when nif_showtip is enabled, I think
notification.szInfoTitle[0] = 0;
notification.dwInfoFlags = NIIF_NONE;
//notification.guidItem = ;
notification.hBalloonIcon = NULL;
StringCchCopy(notification.szTip, ARRAYSIZE(notification.szTip), RCS(messageID));//INFO: msg MUST be less than 128 chars
BOOL ret = Shell_NotifyIcon(NIM_ADD, ¬ification);
if (ret)
this->TrayElements[std::make_pair(hwnd,uID)] = std::make_pair(notification,messageID);//TODO(fran): should we check whether there is an element in that key already?
return ret;
}
BOOL TRAY_HANDLER::DestroyTrayIcon(HWND hwnd, UINT uID) //TODO(fran): should go in destructor too
{
try {
std::pair<NOTIFYICONDATA,WORD> notif_msg = this->TrayElements.at(std::make_pair(hwnd,uID));
BOOL ret = Shell_NotifyIcon(NIM_DELETE, ¬if_msg.first);
DestroyIcon(notif_msg.first.hIcon);
this->TrayElements.erase(std::make_pair(hwnd, uID));
return ret;
}
catch (...) { return FALSE; } //.at() throws
}
BOOL TRAY_HANDLER::UpdateTrayTips()
{
for (auto const& hwnd_msg : this->TrayElements)
this->UpdateTrayTip(hwnd_msg.second.first, hwnd_msg.second.second);
return TRUE;
}
BOOL TRAY_HANDLER::UpdateTrayTip(NOTIFYICONDATA notification, WORD messageID)
{
StringCchCopy(notification.szTip, ARRAYSIZE(notification.szTip), RCS(messageID));
Shell_NotifyIcon(NIM_MODIFY, ¬ification);
return 0;
}
TRAY_HANDLER::TRAY_HANDLER()
{
}
TRAY_HANDLER::~TRAY_HANDLER()
{
}