diff --git a/include/ReWindow/types/Window.h b/include/ReWindow/types/Window.h index 89b6fa3..27dba5a 100644 --- a/include/ReWindow/types/Window.h +++ b/include/ReWindow/types/Window.h @@ -376,6 +376,7 @@ public: /// @param title The notification title. /// @param content The actual text of the notification. /// @param icon The path to the icon to be displayed on the notification, Empty for none. + /// @note On Windows, icon must be a .ico bool Notify(const std::string& title, const std::string& content, const std::filesystem::path& icon = ""); /// @returns True if we are definitely running on a software renderer. diff --git a/src/platform/windows/Window.cpp b/src/platform/windows/Window.cpp index b293cda..8d137ca 100644 --- a/src/platform/windows/Window.cpp +++ b/src/platform/windows/Window.cpp @@ -16,6 +16,42 @@ public: using namespace ReWindow; +// TODO destroy n_data after it's no longer shown. Destroying it early causes the notification to come from explorer. +bool RWindow::Notify(const std::string& title, const std::string& content, const std::filesystem::path& icon) { + NOTIFYICONDATA n_data = {}; + HICON n_icon = nullptr; + + if (!icon.empty()) { + n_icon = (HICON) LoadImageW( + nullptr, + icon.c_str(), + IMAGE_ICON, + 0, 0, + LR_LOADFROMFILE | LR_DEFAULTSIZE + ); + + if (!n_icon) + return false; + } + + n_data.cbSize = sizeof(NOTIFYICONDATA); + n_data.hWnd = platform->hwnd; + n_data.uID = 1; + n_data.uFlags = NIF_INFO | NIF_ICON | NIF_MESSAGE | NIF_TIP; + n_data.uCallbackMessage = WM_USER + 1; + n_data.hIcon = n_icon; + lstrcpy(n_data.szTip, title.c_str()); + lstrcpy(n_data.szInfo, content.c_str()); + lstrcpy(n_data.szInfoTitle, title.c_str()); + n_data.dwInfoFlags = NIIF_USER; + + Shell_NotifyIcon(NIM_ADD, &n_data); + Shell_NotifyIcon(NIM_MODIFY, &n_data); + + //Shell_NotifyIcon(NIM_DELETE, &n_data); + return true; +} + void RWindow::SetSize(int newWidth, int newHeight) { if (!resizable) return;