forked from elifiner/recaps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
trayicon.c
52 lines (45 loc) · 1.2 KB
/
trayicon.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
#include "stdafx.h"
#include "trayicon.h"
void AddTrayIcon(HWND hWnd, UINT uID, UINT uCallbackMsg, UINT uIcon, 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 = LoadSmallIcon(GetModuleHandle(NULL), uIcon);
wcscpy_s(nid.szTip, ARRAYSIZE(nid.szTip), pszToolTip);
Shell_NotifyIcon(NIM_ADD, &nid);
}
void ModifyTrayIcon(HWND hWnd, UINT uID, UINT uIcon, LPTSTR pszToolTip)
{
NOTIFYICONDATA nid = { 0 };
nid.cbSize = sizeof(nid);
nid.hWnd = hWnd;
nid.uID = uID;
if(uIcon != (UINT)-1)
{
nid.hIcon = LoadSmallIcon(GetModuleHandle(NULL), uIcon);
nid.uFlags |= NIF_ICON;
}
if(pszToolTip)
{
wcscpy_s(nid.szTip, ARRAYSIZE(nid.szTip), pszToolTip);
nid.uFlags |= NIF_TIP;
}
if(uIcon != (UINT)-1 || 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);
}
HICON LoadSmallIcon(HINSTANCE hInstance, UINT uID)
{
return (HICON)LoadImage(hInstance, MAKEINTRESOURCE(uID), IMAGE_ICON, 16, 16, 0);
}