pub struct NotifyIcon { /* private fields */ }Expand description
A wrapper around the Windows NOTIFYICONDATAW structure for managing system tray icons in Windows.
Implementations§
Source§impl NotifyIcon
impl NotifyIcon
Sourcepub fn new() -> NotifyIcon
pub fn new() -> NotifyIcon
Creates a new NotifyIcon instance with default values.
This is equivalent to calling NotifyIcon::default().
§Returns
A new NotifyIcon instance with the [NOTIFYICONDATAW::cbSize] field
properly initialized.
Sourcepub fn with_uid(uid: u32) -> NotifyIcon
pub fn with_uid(uid: u32) -> NotifyIcon
Creates a new NotifyIcon instance with given uID.
This is equivalent to calling NotifyIcon::default().
§Returns
A new NotifyIcon instance with the [NOTIFYICONDATAW::cbSize] field
properly initialized.
Sourcepub fn window_handle(self, handle: HWND) -> Self
pub fn window_handle(self, handle: HWND) -> Self
Sets the window handle that will receive notification messages.
This method specifies the window that will receive callback messages when the user interacts with the notification icon. The window handle is required for the notification icon to function properly.
§Arguments
handle- A handle ([HWND]) to the window that will receive notification messages
§Returns
Self for method chaining
Sourcepub fn tip(self, s: impl Into<String>) -> Self
pub fn tip(self, s: impl Into<String>) -> Self
Sets the tooltip text for the notification icon.
The tooltip text is displayed when the user hovers over the icon in the system tray. The text is converted to UTF-16 format and truncated if it exceeds the maximum length. Automatically sets the [NIF_TIP] and [NIF_SHOWTIP] flags.
§Arguments
s- The tooltip text as any type that can be converted into a String
§Returns
Self for method chaining
Sourcepub fn icon(self, icon: HICON) -> Self
pub fn icon(self, icon: HICON) -> Self
Sets the icon for the notification area.
This method assigns an icon handle to the notification icon and automatically sets the [NIF_ICON] flag to indicate that the icon field is valid.
§Arguments
icon- An [HICON] handle to the icon to be displayed in the system tray
§Returns
Self for method chaining
Sourcepub fn balloon_icon(self, icon: HICON) -> Self
pub fn balloon_icon(self, icon: HICON) -> Self
Sets the icon for balloon notifications.
This icon is displayed in balloon tip notifications. The method automatically sets the [NIF_ICON] flag to indicate that the balloon icon field is valid.
§Arguments
icon- An [HICON] handle to the icon to be displayed in balloon notifications
§Returns
Self for method chaining
Sourcepub fn callback_message(self, callback_msg: u32) -> Self
pub fn callback_message(self, callback_msg: u32) -> Self
Sets the callback message identifier for the notification icon.
When the user interacts with the notification icon (clicks, double-clicks, etc.), Windows sends this message to the window procedure. Automatically sets the [NIF_MESSAGE] flag.
§Arguments
callback_msg- The message identifier that will be sent to the window procedure
§Returns
Self for method chaining
Sourcepub fn guid(self, guid: impl Into<GUID>) -> Self
pub fn guid(self, guid: impl Into<GUID>) -> Self
Sets a GUID for the notification icon.
The GUID provides a unique identifier for the notification icon, which can be useful for maintaining icon state across application restarts. Automatically sets the [NIF_GUID] flag.
§Arguments
guid- A 128-bit unsigned integer representing the GUID
§Returns
Self for method chaining
Sourcepub fn timeout(self, timeout: u32) -> Self
pub fn timeout(self, timeout: u32) -> Self
Sets the timeout duration for balloon tip notifications.
This value specifies how long the balloon tip should be displayed before automatically disappearing. The timeout is specified in milliseconds.
Note: This field is deprecated as of Windows Vista. On Vista and later, notification display times are based on system accessibility settings. This field is only effective on Windows 2000 and Windows XP.
The system enforces minimum (10 seconds) and maximum (30 seconds) timeout values.
§Arguments
timeout- Timeout duration in milliseconds (only effective on Windows 2000/XP)
§Returns
Self for method chaining
Sourcepub fn version(self, version: u32) -> Self
pub fn version(self, version: u32) -> Self
Sets the version of the Shell notification icon interface to use.
This method specifies which version of the notification icon interface should be used, which affects the behavior of certain notification features. The version determines whether to use Windows 95-style or newer behavior for icon interactions.
Note: This field shares the same memory location as uTimeout in a
union. This method should only be used when sending a
[NIM_SETVERSION] message via NotifyIcon::notify_set_version. For
balloon notifications, use NotifyIcon::timeout instead.
Common version values:
0(NOTIFYICON_VERSION): Use Windows 95-style behavior (default)3(NOTIFYICON_VERSION_4): Use Windows Vista and later behavior4: Use Windows 7 and later behavior
§Arguments
version- The Shell notification icon interface version to use
§Returns
Self for method chaining
Sourcepub fn notify(&self, message: NOTIFY_ICON_MESSAGE) -> Result<()>
pub fn notify(&self, message: NOTIFY_ICON_MESSAGE) -> Result<()>
Sends a notification message to the Windows shell.
This is the core method that communicates with the Windows shell to perform operations on the notification icon. It calls the [Shell_NotifyIconW] function with the specified message and the current icon data.
§Arguments
message- The type of operation to perform (add, delete, modify, etc.)
§Returns
A windows::core::Result<()> indicating success or failure
§Errors
Returns an error if the Shell_NotifyIconW function fails
Sourcepub fn notify_add(&self) -> Result<()>
pub fn notify_add(&self) -> Result<()>
Adds the notification icon to the system tray.
This method sends a [NIM_ADD] message to add the notification icon to the notification area. The icon will appear in the system tray.
§Returns
A windows::core::Result<()> indicating success or failure
§Errors
Returns an error if the add operation fails
Sourcepub fn notify_delete(&self) -> Result<()>
pub fn notify_delete(&self) -> Result<()>
Removes the notification icon from the system tray.
This method sends a [NIM_DELETE] message to remove the notification icon from the notification area. The icon will disappear from the system tray.
§Returns
A windows::core::Result<()> indicating success or failure
§Errors
Returns an error if the delete operation fails
Sourcepub fn notify_modify(&self) -> Result<()>
pub fn notify_modify(&self) -> Result<()>
Modifies an existing notification icon in the system tray.
This method sends a [NIM_MODIFY] message to update the properties of an existing notification icon. Only the fields that have their corresponding flags set will be updated.
§Returns
A windows::core::Result<()> indicating success or failure
§Errors
Returns an error if the modify operation fails
Sourcepub fn notify_set_focus(&self) -> Result<()>
pub fn notify_set_focus(&self) -> Result<()>
Sets focus to the notification icon.
This method sends a [NIM_SETFOCUS] message to give focus to the notification icon, which can be useful for accessibility purposes.
§Returns
A windows::core::Result<()> indicating success or failure
§Errors
Returns an error if the set focus operation fails
Sourcepub fn notify_set_version(&self) -> Result<()>
pub fn notify_set_version(&self) -> Result<()>
Sets the version of the notification icon interface.
This method sends a [NIM_SETVERSION] message to specify which version of the notification icon interface to use. This affects the behavior of certain notification features.
§Returns
A windows::core::Result<()> indicating success or failure
§Errors
Returns an error if the set version operation fails