From 574f54e32b90c1fdb3a89dd1f73817050f790ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Mon, 14 Feb 2022 20:35:35 +0100 Subject: [PATCH] Added Window.SetIcon --- GlitchyEngine/src/Platform/Windows/WindowsWindow.bf | 12 ++++++++++++ GlitchyEngine/src/Window.bf | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf b/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf index 4c358ee..ebf139f 100644 --- a/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf +++ b/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf @@ -250,6 +250,18 @@ namespace GlitchyEngine [CLink] static extern IntBool IsWindowUnicode(HWND whnd); + public Result SetIcon(StringView filePath) + { + HICON hIcon = LoadImageW(0, filePath.ToScopedNativeWChar!(), .Icon, 0, 0, .LoadFromFile); + if (hIcon == 0) + return .Err; + + // WM_SETICON 0x0080 + SendMessageW(_windowHandle, 0x0080, 1 /* ICON_BIG */, (int)hIcon); + + return .Ok; + } + private static LRESULT MessageHandler(HWND hwnd, uint32 uMsg, WPARAM wParam, LPARAM lParam) { void* windowPtr = (void*)GetWindowLongPtrW(hwnd, GWL_USERDATA); diff --git a/GlitchyEngine/src/Window.bf b/GlitchyEngine/src/Window.bf index c64c978..8263533 100644 --- a/GlitchyEngine/src/Window.bf +++ b/GlitchyEngine/src/Window.bf @@ -110,5 +110,10 @@ namespace GlitchyEngine } public extern void Update(); + + /** + * Sets the Icon of the window to the given file. + */ + public extern Result SetIcon(StringView filePath); } }