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
impl TrayIcon
Sourcepub fn with_primary_id(hwnd: HWND, window_msg_id: Option<u32>) -> Result<Self>
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.
pub fn with_id(id: u16, hwnd: HWND, window_msg_id: Option<u32>) -> Result<Self>
Sourcepub fn with_guid(
guid: GUID,
hwnd: HWND,
window_msg_id: Option<u32>,
) -> Result<Self>
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.
Sourcepub fn readd(&self) -> Result<()>
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.
Sourcepub fn rect(&self) -> Result<RECT>
pub fn rect(&self) -> Result<RECT>
Calls Shell_NotifyIconGetRect().
Sourcepub fn set_tooltip<T>(&mut self, tooltip: Option<T>) -> Result<()>
pub fn set_tooltip<T>(&mut self, tooltip: Option<T>) -> Result<()>
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.
pub fn show(&mut self, show: bool) -> Result<()>
pub fn is_shown(&self) -> bool
Sourcepub fn focus<T>(&mut self) -> Result<()>
pub fn focus<T>(&mut self) -> Result<()>
Performs the NIM_SETFOCUS command.
See https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw.
Sourcepub unsafe fn set_balloon_icon(&mut self, h_icon: Option<HICON>) -> Result<()>
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().
Sourcepub fn set_balloon_uses_large_icon(&mut self, uses_large_icon: bool)
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.
Sourcepub fn show_balloon<T>(
&mut self,
icon: BalloonIcon,
title: Option<T>,
text: T,
realtime_only: bool,
override_quiet_time: bool,
allow_sound: bool,
) -> Result<()>
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<()>
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.