-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtray_icon.c
99 lines (80 loc) · 2.27 KB
/
tray_icon.c
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
98
99
#include "tray_icon.h"
#include <strsafe.h>
/******************************************************************************/
/* Public */
/******************************************************************************/
/******************************************************************************/
BOOL TrayIconAdd(
HWND hWnd,
UINT uID,
UINT uCallbackMsg,
HICON hTrayIcon
)
{
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.uVersion = NOTIFYICON_VERSION;
nid.hWnd = hWnd;
nid.uID = uID;
nid.uFlags = NIF_ICON | NIF_MESSAGE;
nid.uCallbackMessage = uCallbackMsg;
nid.hIcon = hTrayIcon;
return Shell_NotifyIcon(NIM_ADD, &nid);
}
/******************************************************************************/
BOOL TrayUpdateText(
HWND hWnd,
UINT uID,
LPTSTR lptstrNewText
)
{
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.uVersion = NOTIFYICON_VERSION;
nid.hWnd = hWnd;
nid.uID = uID;
nid.uFlags = NIF_TIP;
/* Copy the new string */
if(FAILED(StringCchCopy(nid.szTip, sizeof(nid.szTip) / sizeof(TCHAR),
lptstrNewText)))
{
return FALSE;
}
return Shell_NotifyIcon(NIM_MODIFY, &nid);
}
/******************************************************************************/
BOOL TrayIconRemove(
HWND hWnd,
UINT uID
)
{
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.hWnd = hWnd;
nid.uID = uID;
return Shell_NotifyIcon(NIM_DELETE, &nid);
}
/******************************************************************************/
BOOL TrayIconShowPopupMenu(
HWND hwndParent,
HMENU hMenu
)
{
POINT pt;
/* Get cursor pos */
if(FALSE == GetCursorPos(&pt))
return FALSE;
/* Window receiving the commands needs to be in focus, even if hidden */
SetForegroundWindow(hwndParent);
/* Show popum menu */
return TrackPopupMenuEx(
GetSubMenu(hMenu, 0),
TPM_LEFTBUTTON,
pt.x, pt.y,
hwndParent,
NULL
);
}