-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnotify-icon.hh
81 lines (66 loc) · 1.98 KB
/
notify-icon.hh
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
#pragma once
#include <optional>
#include <string>
#include <Windows.h>
struct notify_icon_id {
HWND callback_hwnd = nullptr;
int32_t callback_id = 0;
std::optional<GUID> guid;
explicit operator bool() const {
return callback_id || guid;
}
};
// Represents options common to add_ and modify_notify_icon.
struct notify_icon_options {
struct notification_options {
// uFlags: NIF_*
std::optional<bool> realtime;
// dwInfoFlags: NIIF_*
std::optional<bool> sound;
std::optional<bool> respect_quiet_time;
std::optional<HICON> icon;
bool large_icon;
std::optional<std::wstring> title;
std::optional<std::wstring> text;
};
// dwState: NIS_*
std::optional<bool> hidden;
std::optional<HICON> icon;
std::optional<std::wstring> tooltip;
std::optional<notification_options> notification;
};
bool add_notify_icon(const notify_icon_id& id,
const notify_icon_options& options,
DWORD callback_message);
bool modify_notify_icon(const notify_icon_id& id,
const notify_icon_options& options);
bool delete_notify_icon(const notify_icon_id& id);
struct NotifyIcon {
notify_icon_id id;
NotifyIcon() = default;
NotifyIcon(const NotifyIcon&) = delete;
NotifyIcon& operator=(const NotifyIcon&) = delete;
NotifyIcon(NotifyIcon&& other) noexcept : id{std::exchange(other.id, {})} {}
NotifyIcon& operator=(NotifyIcon&& other) noexcept {
std::swap(id, other.id);
return *this;
}
bool add(const notify_icon_id& new_id, const notify_icon_options& options,
DWORD callback_message) {
clear();
if (!add_notify_icon(new_id, options, callback_message)) {
return false;
}
id = new_id;
return true;
}
bool modify(const notify_icon_options& options) {
return modify_notify_icon(id, options);
}
bool clear() {
if (!id) return true;
auto old_id = std::exchange(id, {});
return delete_notify_icon(old_id);
}
~NotifyIcon() { clear(); }
};