Skip to content

[rcore][win32] Implement SetWindowIcons() - #6304

Open
Ne0nWinds wants to merge 2 commits into
raysan5:masterfrom
Ne0nWinds:win32-set-window-icon-format
Open

Ne0nWinds wants to merge 2 commits into
raysan5:masterfrom
Ne0nWinds:win32-set-window-icon-format

Conversation

@Ne0nWinds

@Ne0nWinds Ne0nWinds commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
  1. Implements SetWindowIcons(). This function takes an array of icons. Windows can only store two different icon sizes, so the Win32 implementation of SetWindowIcons() selects the best two images based on the resolution that they'll be rendered at.
  2. The format of the incoming images must be R8G8B8A8. This is true for the GLFW backend as well. Both SetWindowIcon() and SetWindowIcons() verify the image's format before setting it as the icon.
  3. If an empty image is passed into either function, they will now reset back to the default Windows icons. This matches the behavior of GLFW.
  4. This PR also includes a significant amount of refactoring to make dealing with icons easier. It's quite easy to leak memory or destroy an icon you're not supposed to. The helper functions DeleteIcons, UpdateIcons, ResetToDefaultWindowsIcons, and ConvertImageToWindowsIcon have been added to make updating the icons less error-prone.

}

// Delete platform.smallIcon and platform.largeIcon
static void DeleteIcons(void)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to avoid some of those extra functions, I think this one and probably UpdateIcons() can be removed and directly implement code, despite a bit of code duplication, they are only used on 2 places.

In general, I prefer to minimize additional functions when possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, actually UpdateIcons() is used in 3 different places:

  1. ResetToDefaultWindowsIcons
  2. SetWindowIcons
  3. SetWindowIcon

DeleteIcons() is used in 4:
The three above + CloseWindow()

The main reason I made DeleteIcons() a function was because you have to check that the large and small icon handles are not pointing to the same underlying resource (otherwise, you'll corrupt the heap with a double-free). This felt like an easy thing to forget.

UpdateIcons() could definitely be inlined without any risk though. I think the two SendMessage calls are pretty self-explanatory.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants