-
Notifications
You must be signed in to change notification settings - Fork 0
/
twTrayIcon.cpp
97 lines (83 loc) · 2.46 KB
/
twTrayIcon.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#define _WIN32_IE 0x0600
#define NOTIFYICONDATA_V3_SIZE 504
#include <windows.h>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <Windowsx.h>
#include "twTrayIcon.h"
extern HINSTANCE instance;
using namespace std;
twTrayIcon::twTrayIcon(twObject *parent, twString text)
{
systemTrayIcon = (NOTIFYICONDATA*)malloc(sizeof(NOTIFYICONDATA));
systemTrayIcon->cbSize = NOTIFYICONDATA_V3_SIZE;
if (parent != NULL)
{
twWindow *window = static_cast<twWindow*>(parent);
systemTrayIcon->hWnd = window->getWindow();
setType(tw::SystemTrayIcon);
setParent(parent);
systemTrayIcon->uCallbackMessage = WM_USER + 1;
systemTrayIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO;
}
else
systemTrayIcon->uFlags = NIF_ICON | NIF_TIP;
strcpy(systemTrayIcon->szInfo, "");
strcpy(systemTrayIcon->szTip, "");
//systemTrayIcon->uVersion = NOTIFYICON_VERSION_4;
m_text = "";
m_message = "";
if (!text.empty())
setText(text);
systemTrayIcon->uID = 0;
}
twTrayIcon::~twTrayIcon()
{
setVisible(false);
}
void twTrayIcon::setIcon(twImage *image)
{
systemTrayIcon->hIcon = image->toIcon();
Shell_NotifyIcon(NIM_MODIFY, systemTrayIcon);
}
void twTrayIcon::setMessage(twString message, twString title, int timeout)
{
if (timeout != 0)
systemTrayIcon->uTimeout = timeout;
strcpy(systemTrayIcon->szInfo, message.c_str());
strcpy(systemTrayIcon->szTip, m_text.c_str());
strcpy(systemTrayIcon->szInfoTitle, title.c_str());
systemTrayIcon->dwInfoFlags = NIIF_NONE;
m_message = message;
m_title = title;
m_timeOut = timeout;
Shell_NotifyIcon(NIM_MODIFY, systemTrayIcon);
}
void twTrayIcon::setText(twString text)
{
m_text = text;
strcpy(systemTrayIcon->szTip, text.c_str());
strcpy(systemTrayIcon->szInfo, m_message.c_str());
strcpy(systemTrayIcon->szInfoTitle, m_title.c_str());
if (m_timeOut != 0)
systemTrayIcon->uTimeout = m_timeOut;
systemTrayIcon->dwInfoFlags = NIIF_NONE;
Shell_NotifyIcon(NIM_MODIFY, systemTrayIcon);
}
twString twTrayIcon::getText()
{
return m_text;
}
twString twTrayIcon::getMessage()
{
return m_message;
}
void twTrayIcon::setVisible(bool visible)
{
if (visible)
Shell_NotifyIcon(NIM_ADD, systemTrayIcon);
else
Shell_NotifyIcon(NIM_DELETE, systemTrayIcon);
}