TrayIcon

Struct TrayIcon 

Source
pub struct TrayIcon { /* private fields */ }
Expand description

An abstraction over Shell_NotifyIconW().

The icon is initially hidden and must be shown with show().

To avoid fetching a low-quality icon, the app’s manifest must declare it as fully DPI-aware (or jump through other hoops to get an appropriately sized icon).

Implementations§

Source§

impl TrayIcon

Source

pub fn with_primary_id(hwnd: HWND, window_msg_id: Option<u32>) -> Result<Self>

Creates a tray icon with ID 0. If you need more than one tray icon, don’t use this function repeatedly.

Source

pub fn with_id(id: u16, hwnd: HWND, window_msg_id: Option<u32>) -> Result<Self>

Source

pub fn with_guid( guid: GUID, hwnd: HWND, window_msg_id: Option<u32>, ) -> Result<Self>

Creates a tray icon identified by a GUID.

Microsoft recommends this over the ID approach. Things like changing the executable path may, however, make a later call to this function with an unchanged GUID fail. See https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataw#troubleshooting.

Source

pub fn readd(&self) -> Result<()>

Adds the icon again.

Only to be called when receiving the window message RegisterWindowMessageW(w!("TaskbarCreated")), which is also sent when explorer.exe restarted.

Source

pub fn rect(&self) -> Result<RECT>

Source

pub unsafe fn set_icon(&mut self, h_icon: HICON) -> Result<()>

Sets a new icon.

§Safety

You are responsibile that the icon is valid and to only free it after it has been replaced or this TrayIcon has been dropped.

Source

pub fn set_tooltip<T>(&mut self, tooltip: Option<T>) -> Result<()>
where T: Into<HSTRING>,

Sets the tooltip text shown when hovering over the tray icon.

Long text will be truncated. See https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataw.

Source

pub fn show(&mut self, show: bool) -> Result<()>

Source

pub fn is_shown(&self) -> bool

Source

pub fn focus<T>(&mut self) -> Result<()>

Source

pub unsafe fn set_balloon_icon(&mut self, h_icon: Option<HICON>) -> Result<()>

Sets a new icon for balloon notifications, when shown with BalloonIcon::User.

None, which is the default, means the same icon as the tray icon.

§Safety

See Self::set_icon().

Source

pub fn set_balloon_uses_large_icon(&mut self, uses_large_icon: bool)

Sets the NIIF_LARGE_ICON flag.

May not change the size of the displayed icon.

See https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataw#niif_large_icon-0x00000020.

Source

pub fn show_balloon<T>( &mut self, icon: BalloonIcon, title: Option<T>, text: T, realtime_only: bool, override_quiet_time: bool, allow_sound: bool, ) -> Result<()>
where T: Into<HSTRING>,

Shows a so-called balloon notification that will automatically be hidden after a while. Not really a balloon anymore on modern Windows versions, but a regular notification.

Long texts will be truncated. For more information on this and the parameters, see https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataw.

Doesn’t return an error, if the notification is suppressed.

Source

pub fn hide_balloon(&mut self) -> Result<()>

Source

pub fn simplifying_translate_window_msg( &mut self, wparam: WPARAM, lparam: LPARAM, ) -> SimplifiedTrayIconMsg

Source

pub fn delete(&mut self) -> Result<()>

Removes the icon from the tray, making this instance unusable for further actions.

Should be used before destroying the associated window.

Trait Implementations§

Source§

impl Drop for TrayIcon

Source§

fn drop(&mut self)

Executes the destructor for this 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> MapSelf for T

Source§

fn map_self<O, T>(self, op: O) -> T
where O: FnOnce(Self) -> T, Self: Sized,

Example: Read more
Source§

fn map_self_or_keep<O>(self, op: O) -> Self
where O: FnOnce(&Self) -> Option<Self>, Self: Sized,

Example: Read more
Source§

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

Source§

type Error = Infallible

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.