Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load icon from file? #38

Closed
GirkovArpa opened this issue Jun 22, 2022 · 3 comments
Closed

Load icon from file? #38

GirkovArpa opened this issue Jun 22, 2022 · 3 comments
Assignees
Labels
bindings Something with the low-level WinAPI bidings enhancement New feature or request

Comments

@GirkovArpa
Copy link

let name: u16 = // ?
let h_icon = HINSTANCE::NULL.LoadImageIcon(name, 16, 16, LR::LOADFROMFILE);

Why is name a u16? Shouldn't a filename string be accepted?

I would like to change the window icon at runtime from a file that isn't included in the resources.

@rodrigocfd rodrigocfd self-assigned this Jun 22, 2022
@rodrigocfd rodrigocfd added the enhancement New feature or request label Jun 22, 2022
@rodrigocfd
Copy link
Owner

rodrigocfd commented Jun 22, 2022

Actually it was more complicated than that... we also must consider the 3 OEM resource flags: OBM, OIC and OCR. This demanded 3 new specific enums to deal with the 3 possibilities: ID, string or OEM resource. Which gives us 9 different possibilities.

I made a quick test and it seems to be correct and working now.

let hicon = HINSTANCE::NULL.LoadImageIcon(
    IdOicStr::from_str("C:\\Temp\\foo.ico"),
    SIZE::new(16, 16),
    co::LR::LOADFROMFILE,
)?;

hicon.DestroyIcon()?; // don't forget this one!

Let me know if this works for you.

rodrigocfd added a commit that referenced this issue Jun 22, 2022
@GirkovArpa
Copy link
Author

Works perfectly!

let h_icon = HINSTANCE::NULL
    .LoadImageIcon(
        IdOicStr::Str(WString::from_str(
            "C:\\Temp\\foo.ico",
        )),
        SIZE::new(16, 16),
        LR::LOADFROMFILE,
    )
    .unwrap();

let window = gui::WindowMain::new(gui::WindowMainOpts {
    class_icon: gui::Icon::Handle(h_icon),
    ..Default::default()
});

@rodrigocfd
Copy link
Owner

Quick tip: IdOicStr enum has a from_str() constructor, so you don't need to construct the WString explicitly:

IdOicStr::from_str("C:\\Temp\\foo.ico")

@rodrigocfd rodrigocfd added the bindings Something with the low-level WinAPI bidings label Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindings Something with the low-level WinAPI bidings enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants