-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from NickvisionApps/shell-notify
`ShellNotification` namespace + `NotifyIcon` class for Windows
- Loading branch information
Showing
13 changed files
with
996 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#ifdef _WIN32 | ||
#ifndef NOTIFYICON_H | ||
#define NOTIFYICON_H | ||
|
||
#define _CRT_SECURE_NO_WARNINGS | ||
#define WM_NOTIFYICON_EVENT (WM_APP + 100) | ||
#define IDM_CONTEXT_MENU (WM_APP + 200) | ||
|
||
#include <filesystem> | ||
#include <map> | ||
#include <windows.h> | ||
#include <shellapi.h> | ||
#include "notifyiconmenu.h" | ||
#include "shellnotificationsenteventargs.h" | ||
|
||
namespace Nickvision::Aura::Notifications | ||
{ | ||
/** | ||
* @brief An icon for the system tray. | ||
* @brief This API is only available on Windows. | ||
*/ | ||
class NotifyIcon | ||
{ | ||
public: | ||
/** | ||
* @brief Constructs a NotifyIcon. | ||
* @param hwnd The HWND handle of the main application window | ||
* @param menu The model for the context menu of the NotifyIcon | ||
* @param hidden Whether or not the NotifyIcon should be hidden by default | ||
* @throw std::logic_error Thrown if Aura::init() was not called yet | ||
* @throw std::runtime_error Thrown if unable to create the NotifyIcon | ||
*/ | ||
NotifyIcon(HWND hwnd, const NotifyIconMenu& contextMenu = { }, bool hidden = false); | ||
/** | ||
* @brief Destructs a NotifyIcon. | ||
*/ | ||
~NotifyIcon() noexcept; | ||
/** | ||
* @brief Hides the icon. | ||
* @return True if icon was hidden, else false | ||
*/ | ||
bool hide() noexcept; | ||
/** | ||
* @brief Shows the icon. | ||
* @return True if icon was shown, else false | ||
*/ | ||
bool show() noexcept; | ||
/** | ||
* @brief Gets the tooltip text of the icon. | ||
* @return The tooltip text | ||
*/ | ||
const std::string& getTooltip() const noexcept; | ||
/** | ||
* @brief Sets the tooltip text of the icon. | ||
* @param tooltip The toolip text | ||
* @return True if the tooltip was updated, else false | ||
*/ | ||
bool setTooltip(const std::string& tooltip) noexcept; | ||
/** | ||
* @brief Shows a notification from the icon. | ||
* @brief Supports the action "open" with action param being a path of a file or folder to open. | ||
* @param e ShellNotificationSentEventArgs | ||
* @return True if notification was shown from the icon | ||
*/ | ||
bool notify(const ShellNotificationSentEventArgs& e) noexcept; | ||
|
||
private: | ||
/** | ||
* @brief Gets a basic NOTIFYICONDATAA struct for this NotifyIcon. | ||
* @return NOTIFYICONDATAA | ||
*/ | ||
NOTIFYICONDATAA getBaseNotifyIconData() noexcept; | ||
/** | ||
* @brief Handles a WM_NOTIFYICON_EVENT message. | ||
* @param wParam WPARAM | ||
* @param lParam LPARAM | ||
* @return LRESULT | ||
*/ | ||
LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) noexcept; | ||
std::string m_className; | ||
bool m_isHidden; | ||
std::string m_tooltip; | ||
NotifyIconMenu m_contextMenu; | ||
HWND m_hwnd; | ||
GUID m_guid; | ||
HMENU m_hmenu; | ||
std::filesystem::path m_openPath; | ||
|
||
private: | ||
static std::map<HWND, NotifyIcon*> m_icons; | ||
/** | ||
* @brief The window procedure for NotifyIcons | ||
* @param hwnd HWND | ||
* @param uMsg UINT | ||
* @param wParam WPARAM | ||
* @param lParam LPARAM | ||
*/ | ||
static LRESULT notifyIconWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) noexcept; | ||
}; | ||
} | ||
|
||
#endif //NOTIFYICON_H | ||
#endif |
Oops, something went wrong.