Skip to content

Commit

Permalink
Merge pull request #58 from olback/hicon
Browse files Browse the repository at this point in the history
Allow use raw HICON object as icon on Windows (Closes #54)
  • Loading branch information
olback authored Apr 7, 2024
2 parents 5374b93 + 890795d commit 16a72ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/api/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use windows_sys::Win32::{
UI::{
Shell::{Shell_NotifyIconW, NIF_ICON, NIF_TIP, NIM_DELETE, NIM_MODIFY, NOTIFYICONDATAW},
WindowsAndMessaging::{
InsertMenuItemW, SetMenuItemInfoW, LoadImageW, PostMessageW, HICON, IMAGE_ICON, LR_DEFAULTCOLOR,
MENUITEMINFOW, MFS_DISABLED, MFS_UNHILITE, MFT_SEPARATOR, MFT_STRING, MIIM_FTYPE,
MIIM_ID, MIIM_STATE, MIIM_STRING, WM_DESTROY,
InsertMenuItemW, LoadImageW, PostMessageW, SetMenuItemInfoW, HICON, IMAGE_ICON,
LR_DEFAULTCOLOR, MENUITEMINFOW, MFS_DISABLED, MFS_UNHILITE, MFT_SEPARATOR, MFT_STRING,
MIIM_FTYPE, MIIM_ID, MIIM_STATE, MIIM_STRING, WM_DESTROY,
},
},
};
Expand Down Expand Up @@ -111,7 +111,10 @@ impl TrayItemWindows {
}

pub fn set_icon(&self, icon: IconSource) -> Result<(), TIError> {
self.set_icon_from_resource(icon.as_str())
match icon {
IconSource::Resource(icon_str) => return self.set_icon_from_resource(icon_str),
IconSource::RawIcon(raw_icon) => self._set_icon(raw_icon),
}
}

pub fn add_label(&mut self, label: &str) -> Result<(), TIError> {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub struct TrayItem(api::TrayItemImpl);
#[derive(Clone)]
pub enum IconSource {
Resource(&'static str),
#[cfg(target_os = "windows")]
RawIcon(windows_sys::Win32::UI::WindowsAndMessaging::HICON),
#[cfg(any(target_os = "macos", all(target_os = "linux", feature = "ksni")))]
Data {
height: i32,
Expand Down

0 comments on commit 16a72ae

Please sign in to comment.