-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrayicon.cpp
51 lines (41 loc) · 1.08 KB
/
trayicon.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
#include "stdafx.h"
#include "trayicon.h"
void AddTrayIcon(HWND hWnd, UINT uID,
UINT uCallbackMsg, HICON hIcon, LPTSTR pszToolTip)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = sizeof(nid);
nid.hWnd = hWnd;
nid.uID = uID;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = uCallbackMsg;
nid.hIcon = hIcon;
wcscpy_s(nid.szTip, sizeof(WCHAR)*64, pszToolTip);
Shell_NotifyIcon(NIM_ADD, &nid);
}
void ModifyTrayIcon(
HWND hWnd, UINT uID, HICON hIcon, LPCTSTR pszToolTip)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = sizeof(nid);
nid.hWnd = hWnd;
nid.uID = uID;
if (hIcon != NULL) {
nid.hIcon = hIcon;
nid.uFlags |= NIF_ICON;
}
if (pszToolTip) {
wcscpy_s(nid.szTip, sizeof(WCHAR)*64, pszToolTip);
nid.uFlags |= NIF_TIP;
}
if (hIcon != NULL || pszToolTip)
Shell_NotifyIcon(NIM_MODIFY, &nid);
}
void RemoveTrayIcon(HWND hWnd, UINT uID)
{
NOTIFYICONDATA nid = {0};
nid.cbSize = sizeof( nid );
nid.hWnd = hWnd;
nid.uID = uID;
Shell_NotifyIcon( NIM_DELETE, &nid );
}