29 #define WIN32_LEAN_AND_MEAN
44 NOTIFYICONDATA*
nid =
nullptr;
52 return static_cast<HWND
>(SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HWND_POINTER,
nullptr));
57 std::u16string u16_string = unicode_cast<std::u16string>(
string);
58 if (u16_string.size() > maxlength) {
59 if ((u16_string[maxlength - 1] & 0xDC00) == 0xD800)
60 u16_string.resize(maxlength - 1);
62 u16_string.resize(maxlength);
64 return std::wstring(u16_string.begin(), u16_string.end());
76 Shell_NotifyIcon(NIM_DELETE,
nid);
87 const HMODULE wesnoth_exe = GetModuleHandle(
nullptr);
88 if (wesnoth_exe ==
nullptr) {
92 const HRSRC group_icon_info = FindResource(wesnoth_exe, TEXT(
"WESNOTH_ICON"), RT_GROUP_ICON);
93 if (group_icon_info ==
nullptr) {
97 HGLOBAL hGlobal = LoadResource(wesnoth_exe, group_icon_info);
98 if (hGlobal ==
nullptr) {
102 const PBYTE group_icon_res =
static_cast<PBYTE
>(LockResource(hGlobal));
103 if (group_icon_res ==
nullptr) {
107 const int nID = LookupIconIdFromDirectoryEx(group_icon_res, TRUE, 32, 32, LR_DEFAULTCOLOR);
112 const HRSRC icon_info = FindResource(wesnoth_exe, MAKEINTRESOURCE(nID), MAKEINTRESOURCE(3));
113 if (icon_info ==
nullptr) {
117 hGlobal = LoadResource(wesnoth_exe, icon_info);
118 if (hGlobal ==
nullptr) {
122 const PBYTE icon_res =
static_cast<PBYTE
>(LockResource(hGlobal));
123 if (icon_res ==
nullptr) {
127 const HICON icon = CreateIconFromResource(icon_res, SizeofResource(wesnoth_exe, icon_info), TRUE, 0x00030000);
128 if (icon ==
nullptr) {
133 if (window ==
nullptr) {
140 nid =
new NOTIFYICONDATA;
141 memset(
nid, 0,
sizeof(*
nid));
142 nid->cbSize = NOTIFYICONDATA_V2_SIZE;
144 nid->uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
145 nid->dwInfoFlags = NIIF_USER;
146 nid->uVersion = NOTIFYICON_VERSION;
150 nid->hBalloonIcon = icon;
151 lstrcpyW(
nid->szTip, wtip.c_str());
154 return Shell_NotifyIcon(NIM_ADD,
nid) != FALSE;
162 nid->uFlags |= NIF_INFO;
167 return Shell_NotifyIcon(NIM_MODIFY,
nid) != FALSE;
172 static const int ELIPSIS_LENGTH = 3;
186 if (window ==
nullptr) {
190 if (IsIconic(window)) {
191 ShowWindow(window, SW_RESTORE);
193 SetForegroundWindow(window);
198 bool show(std::string title, std::string message)
203 if (!tray_icon_exist) {
205 if (!tray_icon_created) {
207 if (memory_allocated) {
228 case NIN_BALLOONUSERCLICK:
233 case NIN_BALLOONTIMEOUT:
static std::string _(const char *str)
Contains the implementation details for lexical_cast and shouldn't be used directly.
void ellipsis_truncate(std::string &str, const std::size_t size)
Truncates a string to a given utf-8 character count and then appends an ellipsis.
SDL_Window * get_window()
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::wstring string_to_wstring(const std::string &string, std::size_t maxlength)
void adjust_length(std::string &title, std::string &message)
constexpr unsigned int WM_TRAYNOTIFY
constexpr std::size_t MAX_TITLE_LENGTH
bool set_tray_message(const std::string &title, const std::string &message)
void switch_to_wesnoth_window()
constexpr std::size_t MAX_MESSAGE_LENGTH
bool show(std::string title, std::string message)
Displays a tray notification.
bool message_hook(const MSG &msg)
Frees resources when a notification disappears, switches user to the wesnoth window if the notificati...
Contains a wrapper class for the SDL_Window class.