Skip to main content

NotifyIcon

Struct NotifyIcon 

Source
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

Source

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.

Source

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.

Source

pub fn flag(self, flag: NOTIFY_ICON_DATA_FLAGS) -> Self

Sets a flag in the notification icon data structure.

This method uses a bitwise OR operation to add the specified flag to the existing flags in the [NOTIFYICONDATAW::uFlags].

§Arguments
  • flag - A [NOTIFY_ICON_DATA_FLAGS] value to be added to the current flags
§Returns

Self for method chaining

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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 behavior
  • 4: Use Windows 7 and later behavior
§Arguments
  • version - The Shell notification icon interface version to use
§Returns

Self for method chaining

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl Default for NotifyIcon

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.