Skip to content

Fix/wm dpichanged handler - #25

Open
electricmessiah wants to merge 5 commits into
mgelsinger:mainfrom
electricmessiah:fix/wm-dpichanged-handler
Open

Fix/wm dpichanged handler#25
electricmessiah wants to merge 5 commits into
mgelsinger:mainfrom
electricmessiah:fix/wm-dpichanged-handler

Conversation

@electricmessiah

@electricmessiah electricmessiah commented Jul 19, 2026

Copy link
Copy Markdown

fixes toolbar font size on different DPI displays

…ss icons

Replaces the native menu bar with a custom-drawn toolbar row so quick-access
icon buttons can share the same line as File/Edit/View. File/Edit/View are
now flat buttons that open the same native submenus via TrackPopupMenu (all
existing menu content, IDM_* command routing, and keyboard behavior within
each dropdown is unchanged); New and Save As are icon buttons using Segoe
Fluent Icons glyphs, with hover tooltips.

- Custom BS_OWNERDRAW buttons throughout: standard BS_PUSHBUTTON always
  self-draws its 3D face using system colors and ignores WM_CTLCOLORBTN
  regardless of theme, so dark-themed buttons need full owner-draw
  (draw_toolbar_row_button).
- The app's HMENU is now built once and kept in AppState (main_menu) instead
  of attached via SetMenu/CreateWindowExW; every menu-manipulation helper
  (checkmarks, enable/disable, Recent Files rebuild) was updated to read it
  from state directly. This also fixes a related bug: those helpers
  previously read the menu via GetWindowLongPtrW(hwnd, GWLP_USERDATA), which
  isn't set until after create_children() returns — so initial checkmark
  sync at startup was silently a no-op until the user toggled the setting
  manually once.
Font was baked in on first use, often during early WM_CREATE/WM_SIZE
before Windows reports the window's final per-monitor DPI. Button
boxes already re-layout dynamically and pick up the corrected DPI,
but the glyph font stayed frozen at the wrong (usually 96 DPI) size,
so icons rendered undersized relative to their buttons on interactive
launches that hit the transient DPI window.
Dark theme colors the toolbar row the same background as the editor
and tabs below it, so without a seam the row visually blends into the
content area. Draws a DPI-scaled 1px line in a brighter dedicated
shade along the bottom edge to keep the separation visible.
Two compounding bugs, both surfacing as the toolbar row (labels and/or
icons) rendering cut off or wrong-sized after dragging the window
between monitors with different DPI:

- WM_DPICHANGED was never handled. Moving a window to a monitor with
  a different DPI doesn't always change its pixel width/height (a
  pure move can leave both unchanged), so WM_SIZE never fires and
  none of our DPI-dependent layout code re-runs at all. Added a
  handler that resizes/repositions to Windows' suggested rect and
  explicitly forces a re-layout rather than relying on a WM_SIZE that
  may never come.

- Separately, and worse: layout_toolbar_row_labels never existed.
  The File/Edit/View label buttons were positioned once at creation
  time and never repositioned on any WM_SIZE, DPI-change-driven or
  otherwise — only the icon buttons (New/Save As/Print) had a
  re-layout function. Added layout_toolbar_row_labels, matching the
  existing layout_toolbar_row_icons pattern, and wired it into the
  toolbar row's WM_SIZE handler.
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.

1 participant