Skip to content

Commit 20710da

Browse files
committed
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.
1 parent 7c08b32 commit 20710da

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ values and their textual representations. ([#1377])
251251
- All Image formats are now optional, reducing compile time and binary size by default ([#1340] by [@JAicewizard])
252252
- The `Cursor` API has changed to a stateful one ([#1433] by [@jneem])
253253
- Part of the `SAVE_FILE` command is now `SAVE_FILE_AS` ([#1463] by [@jneem])
254+
- Windows: Use custom application icon, if present ([#????] by [@tay64])
254255

255256
### Deprecated
256257
- Parse widget (replaced with `Formatter` trait) ([#1377] by [@cmyr])

druid-shell/src/backend/windows/application.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ use winapi::shared::ntdef::LPCWSTR;
2626
use winapi::shared::windef::{DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, HCURSOR, HWND};
2727
use winapi::shared::winerror::HRESULT_FROM_WIN32;
2828
use winapi::um::errhandlingapi::GetLastError;
29+
use winapi::um::libloaderapi::GetModuleHandleW;
2930
use winapi::um::shellscalingapi::PROCESS_PER_MONITOR_DPI_AWARE;
3031
use winapi::um::winnls::GetUserDefaultLocaleName;
3132
use winapi::um::winnt::LOCALE_NAME_MAX_LENGTH;
3233
use winapi::um::winuser::{
3334
DispatchMessageW, GetAncestor, GetMessageW, LoadIconW, PeekMessageW, PostMessageW,
3435
PostQuitMessage, RegisterClassW, TranslateAcceleratorW, TranslateMessage, GA_ROOT,
35-
IDI_APPLICATION, MSG, PM_NOREMOVE, WM_TIMER, WNDCLASSW,
36+
MAKEINTRESOURCEW, MSG, PM_NOREMOVE, WM_TIMER, WNDCLASSW,
3637
};
3738

3839
use piet_common::D2DLoadedFonts;
@@ -90,7 +91,7 @@ impl Application {
9091
.is_ok()
9192
{
9293
let class_name = CLASS_NAME.to_wide();
93-
let icon = unsafe { LoadIconW(0 as HINSTANCE, IDI_APPLICATION) };
94+
let icon = unsafe { LoadIconW(GetModuleHandleW(0 as LPCWSTR), MAKEINTRESOURCEW(1)) };
9495
let wnd = WNDCLASSW {
9596
style: 0,
9697
lpfnWndProc: Some(window::win_proc_dispatch),

0 commit comments

Comments
 (0)