fix(windows): pre-multiply alpha when setting menu item icons to fix black background#290
Open
HarshalPatel1972 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Windows 11 menu item icons rendering with a black background by generating a 32-bit DIB-backed bitmap (alpha-capable) and pre-multiplying pixel RGB values by alpha before assigning the bitmap to menu items.
Changes:
- Replaced
CreateCompatibleBitmapwithCreateDIBSectionfor menu item icon bitmaps (preserves alpha). - Added per-pixel alpha pre-multiplication on the DIB’s backing buffer prior to returning the
HBITMAP.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…andle leak, and clarify alpha comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #267
Problem
Menu item icons render with a black background on Windows 11 when the
icon has transparent pixels. The tray icon itself renders correctly,
and disabled menu items also render correctly — only enabled menu items
are affected.
The root cause is that Windows GDI expects pre-multiplied alpha for
HBITMAP objects used in menus. The previous code used
CreateCompatibleBitmap which doesn't handle alpha, causing transparent
pixels to render as black.
Fix
Replaced CreateCompatibleBitmap with CreateDIBSection and added
alpha pre-multiplication for each pixel before the bitmap is passed
to SetMenuItemInfo:
This matches the format Windows expects for alpha-blended menu bitmaps.
Tested on
Windows 11 23H2