Shell_NotifyIconA does not display the HICON provided

106 views Asked by At

I am trying to create a simple tray icon using the windows-rs rust crate.

When calling Shell_NotifyIconA(NIM_ADD, &data); one is created, however, by default it has a blank image. I have loaded an .ico via LoadImageW, however, still nothing.

What am I missing?

Full code:

use std::ffi::OsString;

use windows::Win32::Foundation::{HINSTANCE, GetLastError};
use windows::Win32::UI::Shell::{Shell_NotifyIconA, NOTIFY_ICON_MESSAGE, NIM_ADD, NOTIFYICON_VERSION_4, NOTIFYICONDATAA};
use windows::Win32::UI::WindowsAndMessaging::{LoadImageW, IMAGE_ICON, LR_DEFAULTSIZE, LR_LOADFROMFILE, DestroyIcon, HICON};

fn main() -> anyhow::Result<()> {
    unsafe {
        let mut data = NOTIFYICONDATAA::default();
        let icon_handle = LoadImageW(HINSTANCE::default(), &OsString::from("icon.ico").into(), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE)?;

        println!("icon handle {:#?}", icon_handle); // icon handle 363530555
        data.hIcon = HICON(icon_handle.0);
        println!("error? {:#?}", GetLastError()); // 0

        Shell_NotifyIconA(NIM_ADD, &data);
    }
    
    Ok(())
}
0

There are 0 answers