rust-windowing / rust-windowing/winit
Add a windows specific method for setting the window icons based on the embedded exe icon.
Open
Nobody has claimed this yet.
DS - win32
S - enhancement
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
Description
Using the following code you can get the icon for the running process, then call WM_SETICON to apply it to any window.
This prevents storing duplicate copies of the icon just to also reuse it for the window icon.
let Ok(path) = std::env::current_exe() else {
return 0;
};
let Ok(path) = U16CString::from_os_str(path.as_os_str()) else {
return 0;
};
// SAFETY:
// Path is checked to be a valid u16cstring above. The result is checked for errors where
// 1 = not an icon or exe.
// 0 = any other error.
// While this obviously leaks the icon, the icon won't change for the lifetime of the program and can be used in more
// than one window during the lifetime of the program.
let icon = unsafe { ExtractIconW(GetModuleHandleW(std::ptr::null()), path.as_ptr(), 0) };
if icon as usize <= 1 {
return 0;
}
Relevant platforms
Windows
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the issue's Windows example using current_exe, GetModuleHandleW, ExtractIconW, and WM_SETICON. Trace the existing window-icon APIs and add a Windows-specific method that reuses the embedded executable icon for a window, with behavior matching the requested icon application.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100