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

Windows: Allow setting a window Icon #1162

Open
MTRNord opened this issue Aug 27, 2020 · 11 comments
Open

Windows: Allow setting a window Icon #1162

MTRNord opened this issue Aug 27, 2020 · 11 comments

Comments

@MTRNord
Copy link

MTRNord commented Aug 27, 2020

It would be nice to set a Window Icon which shows both in the title bar and in the taskbar.

For the exe itself https://github.com/mxre/winres does work fine. For the Window itself this is not yet clear.

@MTRNord
Copy link
Author

MTRNord commented Aug 27, 2020

As a hint I guess this SO awnser for C should give a starting point https://stackoverflow.com/a/45727762/4929236

@MTRNord
Copy link
Author

MTRNord commented Aug 27, 2020

This seems to show the missing pieces in winapi-rs retep998/winapi-rs#122

Seems like https://github.com/linebender/druid/blob/master/druid-shell/src/platform/windows/window.rs#L1209 needs to construct WNDCLASSEXW from scratch instead of using that function as that function does not expose hIcon to us

@MTRNord
Copy link
Author

MTRNord commented Aug 27, 2020

An alternative is to load it after creating the window using https://docs.rs/winapi/0.3.9/winapi/um/winuser/fn.LoadImageW.html

@MTRNord
Copy link
Author

MTRNord commented Aug 27, 2020

Taken from the zulip chat (Just to track it here):

I think we're looking for SetClassLong to the icon offset, or SendMessage(hWnd, WM_SETICON, [big or small], handle).. either way, I do think we'll need to get a handle to it, so LoadImage or LoadIcon will be involved. (source)

@cmyr
Copy link
Member

cmyr commented Aug 27, 2020

We definitely want to be able to customize the app icon on all platforms. At least in the mac case this is mostly a case of just putting a file with the right name in the right place in the app bundle, and including it in the info.plist file; other platforms may require more code.

@raphlinus
Copy link
Contributor

Setting the desktop icon on Windows similarly requires storing the icon in the application's manifest, which is analogous to Info.plist. That's a different issue than the titlebar/taskbar, but want to clarify because I think these often go together.

@MTRNord
Copy link
Author

MTRNord commented Aug 28, 2020

@raphlinus thats easily done using the above linked winres and a build.rs :) That already works

@Chaostheorie
Copy link

The tracking issue for such files and their handling is #397

@Kethku
Copy link
Contributor

Kethku commented Jul 28, 2021

Just wanting to chime in here, there are two separate problems with icons: setting them in the application manifest and or app bundle, and setting the icon for the window itself.

The former sets the icon on the executable itself, and the latter sets it on the window like
image

I think these should be addressed separately.

@kevin406972552
Copy link

Very cumbersome method

@zedseven
Copy link
Contributor

I've gotten window icons set up when building for Windows, in my project. I thought I'd share my findings here along with the relevant code, to aid anyone who wants to implement this before Druid officially supports it.

Here's a screencap of the titlebar:
image

And in the Alt+Tab dialog: (the Windows API supports setting different icons for Alt+Tab than for window titlebars, though I set the same for both here)
image

Below is the pertinent code.
https://github.com/zedseven/config-loader/blob/878ced0cd4a097652187953facaaaf0f849bb32d/src/gui.rs#L273-L327
https://github.com/zedseven/config-loader/blob/878ced0cd4a097652187953facaaaf0f849bb32d/build.rs#L29-L41

There's a few considerations, however:

  • Currently I'm relying on my changes for Send the WindowHandle with AppDelegate::window_added. #2119 to get a WindowHandle upon window creation for setting the icon.
    • As long as you can get a RawWindowHandle though, it doesn't matter how you get it.
  • This requires using Druid's raw-window-handle feature.
  • The icon being set at runtime is loaded directly from the executable. (though the Windows API does provide support for loading from a file)

Useful links I found when looking into this:

I haven't worked with MacOS or Linux as of yet as GUI support for my project is still in it's early stages, but if I come up with a solution for any other platforms that I'm happy with I'll mention it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants