notify-icon-rs
A safe, ergonomic Rust wrapper around the Windows Shell_NotifyIcon API for managing system tray icons on Windows platforms.
This library provides a high-level interface to create, modify, and manage notification icons in the Windows system tray. It handles the complexities of the underlying Windows API while providing a builder pattern for easy configuration and Rust-style error handling.
Features
- Safe wrapper: Memory-safe abstraction over the raw Windows API
- Builder pattern: Fluent, chainable API for configuring notification icons
- Error handling: Proper Rust
Resulttypes instead of raw Windows error codes - UTF-16 handling: Automatic conversion of Rust strings to Windows-compatible UTF-16
- Version support: Support for different Windows notification icon interface versions
- Comprehensive functionality: Support for tooltips, balloon notifications, GUIDs, and more
Supported Windows Versions
This library supports Windows 95 and later versions, with enhanced functionality on:
- Windows Vista and later (improved balloon notification behavior)
- Windows 7 and later (additional notification features)
Platform Requirements
- Target: Windows only (
#[cfg(windows)]should be used when integrating) - Dependencies: Requires the
windowscrate for Windows API bindings
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
or invoke command:
Quick Start
use HWND;
use UI;
use NotifyIcon;
// Create and configure a notification icon
let icon = new
.window_handle // Window to receive messages
.tip // Tooltip text
.icon // Icon to display
.callback_message; // Message ID for callbacks
// Add the icon to the system tray
icon.notify_add?;
// Later, remove the icon
icon.notify_delete?;
Usage Examples
Using GUIDs for Icon Persistence
use GUID;
let icon = new
.window_handle
.guid
.tip
.icon;
icon.notify_add?;
Setting Interface Version for Enhanced Features
// Use Windows Vista+ behavior
let icon = new
.window_handle
.version // NOTIFYICON_VERSION_4
.tip;
icon.notify_add?;
icon.notify_set_version?; // Apply the version setting
Modifying Existing Icons
// Change the tooltip of an existing icon
let updated_icon = icon.tip;
updated_icon.notify_modify?;
Message Handling
When users interact with the notification icon, Windows sends messages to the specified window. Here's a common message handling pattern:
use UI;
// In your window procedure
match msg
Error Handling
All notification operations return windows::core::Result<()>.
match icon.notify_add
Thread Safety
The NotifyIcon struct is safe to use across threads.
Limitations
- Windows only: This library only works on Windows platforms
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
MIT License - see the LICENSE file for details.
Acknowledgments
- Built on top of the excellent
windowscrate