From 66ece0e97ea6860d58a7833c411c011d0855c1e9 Mon Sep 17 00:00:00 2001 From: tay64 Date: Thu, 13 Oct 2022 14:34:58 +0300 Subject: [PATCH] Use custom application icon on Windows, if present. On Windows, if the executable contains an icon resource with id 1, this icon will be used in the Taskbar and in the titlebar of Druid windows. If there is no such icon resource, the default application icon IDI_APPLICATION will be used (as before this change). Adding a custom icon: one way is to use the [winres crate](https://crates.io/crates/winres) and follow the guide in its README; `winres::WindowsResource::set_icon()` adds an icon with id 1. Non-Windows back-ends are not modified. --- CHANGELOG.md | 2 ++ druid-shell/src/backend/windows/application.rs | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 536c8979ed..883814f96c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -251,6 +251,7 @@ values and their textual representations. ([#1377]) - All Image formats are now optional, reducing compile time and binary size by default ([#1340] by [@JAicewizard]) - The `Cursor` API has changed to a stateful one ([#1433] by [@jneem]) - Part of the `SAVE_FILE` command is now `SAVE_FILE_AS` ([#1463] by [@jneem]) +- Windows: Use custom application icon, if present ([#2274] by [@tay64]) ### Deprecated - Parse widget (replaced with `Formatter` trait) ([#1377] by [@cmyr]) @@ -862,6 +863,7 @@ Last release without a changelog :( [#2203]: https://github.com/linebender/druid/pull/2203 [#2235]: https://github.com/linebender/druid/pull/2235 [#2247]: https://github.com/linebender/druid/pull/2247 +[#2274]: https://github.com/linebender/druid/pull/2274 [Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master [0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0 [0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0 diff --git a/druid-shell/src/backend/windows/application.rs b/druid-shell/src/backend/windows/application.rs index 084757b5f6..d911154bad 100644 --- a/druid-shell/src/backend/windows/application.rs +++ b/druid-shell/src/backend/windows/application.rs @@ -26,13 +26,14 @@ use winapi::shared::ntdef::LPCWSTR; use winapi::shared::windef::{DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, HCURSOR, HWND}; use winapi::shared::winerror::HRESULT_FROM_WIN32; use winapi::um::errhandlingapi::GetLastError; +use winapi::um::libloaderapi::GetModuleHandleW; use winapi::um::shellscalingapi::PROCESS_PER_MONITOR_DPI_AWARE; use winapi::um::winnls::GetUserDefaultLocaleName; use winapi::um::winnt::LOCALE_NAME_MAX_LENGTH; use winapi::um::winuser::{ DispatchMessageW, GetAncestor, GetMessageW, LoadIconW, PeekMessageW, PostMessageW, PostQuitMessage, RegisterClassW, TranslateAcceleratorW, TranslateMessage, GA_ROOT, - IDI_APPLICATION, MSG, PM_NOREMOVE, WM_TIMER, WNDCLASSW, + MAKEINTRESOURCEW, MSG, PM_NOREMOVE, WM_TIMER, WNDCLASSW, }; use piet_common::D2DLoadedFonts; @@ -90,7 +91,7 @@ impl Application { .is_ok() { let class_name = CLASS_NAME.to_wide(); - let icon = unsafe { LoadIconW(0 as HINSTANCE, IDI_APPLICATION) }; + let icon = unsafe { LoadIconW(GetModuleHandleW(0 as LPCWSTR), MAKEINTRESOURCEW(1)) }; let wnd = WNDCLASSW { style: 0, lpfnWndProc: Some(window::win_proc_dispatch),