Repository navigation
Expand file tree
/
Copy pathTrayIcon.cpp
More file actions
89 lines (75 loc) · 1.43 KB
/
Copy pathTrayIcon.cpp
File metadata and controls
89 lines (75 loc) · 1.43 KB
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
#include "stdafx.h"
#include "TrayIcon.h"
Tray_Map mTrays;
UINT TrayIcon::uId = 0;
TrayIcon::TrayIcon(HWND hWnd) : visible(FALSE)
{
ZeroMemory(&nid, sizeof(NOTIFYICONDATA));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = uId ? ++uId : uId = 1;
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
nid.uCallbackMessage = TRAYICON_MESSAGE;
nid.hIcon = GetWindowIcon(hWnd);
GetWindowText(hWnd, nid.szTip, ARRAYSIZE(nid.szTip));
nid.uVersion = NOTIFYICON_VERSION;
}
TrayIcon::TrayIcon(const TrayIcon& other) : nid(other.nid), visible(FALSE)
{
}
TrayIcon::~TrayIcon()
{
Hide();
}
void TrayIcon::SetCallBackMessage(UINT uMessage)
{
nid.uCallbackMessage = uMessage;
}
UINT TrayIcon::Show()
{
if (Shell_NotifyIcon(NIM_ADD, &nid))
{
visible = TRUE;
return nid.uID;
}
return NULL;
}
BOOL TrayIcon::Hide()
{
if (!visible)
{
return TRUE;
}
BOOL hidden = Shell_NotifyIcon(NIM_DELETE, &nid);
if (hidden)
{
visible = FALSE;
}
return hidden;
}
// Private
HICON TrayIcon::GetWindowIcon(HWND hWnd)
{
HICON hIcon = NULL;
hIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, NULL);
if (hIcon)
{
return hIcon;
}
hIcon = (HICON)GetClassLongPtr(hWnd, GCLP_HICONSM);
if (hIcon)
{
return hIcon;
}
hIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, NULL);
if (hIcon)
{
return hIcon;
}
hIcon = (HICON)GetClassLongPtr(hWnd, GCLP_HICON);
if (hIcon)
{
return hIcon;
}
return LoadIcon(NULL, IDI_APPLICATION);
}