Improve MSW menu dark-mode rendering and Windows 11 menu appearance (PR #26053)

23 views
Skip to first unread message

Mohmed abdel-fattah

unread,
Dec 24, 2025, 3:16:11 AM (2 days ago) Dec 24
to wx-...@googlegroups.com, Subscribed

Description

This PR fixes several MSW menu rendering issues observed in dark mode and on Windows 11.
1- It includes changes to make menu breaks render correctly in dark mode (owner-drawn).
2- applies dark-mode-aware menu background colors, adjusts owner-drawn menu item drawing (text color fallbacks).
3- applies Windows 11 DWM window attributes to popup menu windows to get rounded corners and proper border color.

High-level items implemented or touched by this PR:

  • Force owner-draw for menu-break items when dark mode is active so they render correctly.
  • Use theme-aware colors for popup menu background and menu item text; add fallbacks when dark-theme values are unavailable.
  • change popup menu background .
  • Update theme handle usage (supply dark-mode theme identifiers where applicable).
  • Set DWM attributes (rounded corners and border color) for menu windows on Windows 11+ dynamically.

Changes Proposed

  • src/msw/menu.cpp
    • Include darkmode and uxtheme private headers.
    • When m_doBreak is set and dark mode is active, mark the item owner-drawn.
    • On menu creation, when wxMSWDarkMode is active and owner-drawn is used, query theme popup background color.
  • src/msw/menuitem.cpp
    • Include darkmode header.
    • Use dark-mode-aware theme string when creating wxUxThemeHandle).
    • Obtain TMT_TEXTCOLOR from theme in dark mode, with fallback to system menu text color if not available.
  • src/msw/window.cpp
    • Dynamically call DwmSetWindowAttribute to set DWMWA_WINDOW_CORNER_PREFERENCE (rounded corners) and DWMWA_BORDER_COLOR.
    • Load dwmapi.dll and DwmSetWindowAttribute with LoadLibrary/GetProcAddress to avoid link dependency.

Motivation and Context

  • Dark-mode menus and menu breaks displayed incorrectly with default rendering; forcing owner-draw and using theme colors addresses incorrect backgrounds and text colors in dark themes.
  • Windows 11 introduced different menu visuals (rounded corners, border colors). Applying DWM attributes to popup menu windows improves visual consistency for native-looking menus.
  • The changes aim to preserve visual correctness across themes and OS versions while avoiding hard dependencies on newer APIs at link time.

How Has This Been Tested?

  • Built and ran on Windows 11 (verify rounded corners and border color on popup menus).
  • Built and ran on Windows 10 (verify no regressions; attributes not applied).
  • Tested owner-drawn menu breaks in dark mode and light mode (verify layout and separators).
  • Verified submenu arrows render for owner-drawn popup items at multiple DPIs.
  • Verified no GDI resource leaks (monitor GDI handles while repeatedly opening/closing menus).

Screenshots

before
Screenshot.2025-12-24.101158.png (view on web)

after
Screenshot.2025-12-24.100600.png (view on web)

Developer notes and required follow-ups

Address the following soon after merging this PR:

  • HBRUSH ownership and GDI leaks

    • The PR creates HBRUSH via CreateSolidBrush and passes it to SetMenuInfo. Confirm whether the system copies the brush or expects the app to keep it alive. If the app owns it, ensure it is deleted at the appropriate lifecycle point (menu destruction) to avoid GDI leaks. Consider caching brushes keyed by color and cleaning them up at process/owner cleanup.
  • Initialization placement

    • The menu background setting is done in Create(); evaluate whether it should be moved to wxMenu::Init() or a more central
  • Visual correctness

Related issues

Fixes #25577
Fixes #22518

Suggested reviewers

@vadz


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/26053

Commit Summary

  • e2dc406 Fix menu rounded corners in Windows 11 and higher
  • a357f52 Set dark mode menu background color and if menu has break Set it OwnerDrawn at darkMode
  • 713363d Add DarkMode Theme to OwnerDrawn Menu Items

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26053@github.com>

Mohmed abdel-fattah

unread,
Dec 24, 2025, 4:08:01 AM (2 days ago) Dec 24
to wx-...@googlegroups.com, Push

@memoarfaa pushed 1 commit.

  • e35d792 fix trailing whitespace build errors


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26053/before/713363d9a8927fbb0aa94a8f2030280990b752a5/after/e35d79222ea969aaca4716250f4fac59ece184ad@github.com>

Mohmed abdel-fattah

unread,
Dec 25, 2025, 11:09:48 AM (22 hours ago) Dec 25
to wx-...@googlegroups.com, Push

@memoarfaa pushed 1 commit.

  • 2862100 add submenu arrows render for owner-drawn popup items at dark mode.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26053/before/e35d79222ea969aaca4716250f4fac59ece184ad/after/28621004f21b1728365709b0206015b7f19f42c7@github.com>

Mohmed abdel-fattah

unread,
Dec 25, 2025, 11:18:33 AM (22 hours ago) Dec 25
to wx-...@googlegroups.com, Push

@memoarfaa pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26053/before/28621004f21b1728365709b0206015b7f19f42c7/after/7ac12112401e4a1ed77c753711ab3683e708101c@github.com>

Mohmed abdel-fattah

unread,
Dec 25, 2025, 12:13:49 PM (21 hours ago) Dec 25
to wx-...@googlegroups.com, Push

@memoarfaa pushed 1 commit.

  • b586e98 Fix IsActive missing "()" build error


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26053/before/7ac12112401e4a1ed77c753711ab3683e708101c/after/b586e98fb3e76b8e0f65a84d3da75ed0a517c9c6@github.com>

Reply all
Reply to author
Forward
0 new messages