Skip to content

Implement dark mode using win32-darkmodelib#1203

Open
lostindark wants to merge 3 commits into
zufuliu:mainfrom
lostindark:main
Open

Implement dark mode using win32-darkmodelib#1203
lostindark wants to merge 3 commits into
zufuliu:mainfrom
lostindark:main

Conversation

@lostindark

Copy link
Copy Markdown
Contributor

Vendor ozone10/win32-darkmodelib source files directly in darkmodelib/ to provide native Windows dark mode support for Notepad4's UI chrome, tied to the existing Style Theme (Default/Dark) setting.

Features:

  • Dark title bar, menu bar, context menus (via system dark mode APIs)
  • Dark toolbar, rebar, status bar with darkmodelib subclassing
  • Dark tooltips and scrollbars
  • All dialogs automatically themed via WH_CALLWNDPROCRET hook on WM_INITDIALOG (no per-dialog-proc changes needed)
  • Toolbar Customize dialog fixed with temporary SetSysColors override
  • Custom color hierarchy for visual depth: Editor #1E1E1E / Dialogs #252526 / Toolbar #2D2D2D / Controls #383838
  • View colors for list boxes, list views, tree views, and headers
  • Theme switching via View > Style Theme toggles dark mode on/off
  • WM_SETTINGCHANGE handled for system dark/light mode changes

@zufuliu

zufuliu commented Apr 7, 2026

Copy link
Copy Markdown
Owner

Please wait a bit, looks win32-darkmodelib has too many codes (main branch 1M lines, old win32-darkmode only has hundred lines).

D:\Libs\win32-darkmodelib\src>perl d:\Dev\MSYS2\opt\bin\cloc.pl .
      27 text files.
      27 unique files.
       0 files ignored.

github.com/AlDanial/cloc v 2.08  T=0.08 s (322.6 files/s, 164987.9 lines/s)
---------------------------------------------------------------------------------------
Language                             files          blank        comment           code
---------------------------------------------------------------------------------------
C++                                     10           1264           3192           6641
C/C++ Header                            15            366            589           1532
Windows Module Definition                1              0              0            183
Windows Resource File                    1              2              4             34
---------------------------------------------------------------------------------------
SUM:                                    27           1632           3785           8390
---------------------------------------------------------------------------------------

I don't understand why it's need to subcalss all common controls.

@lostindark

Copy link
Copy Markdown
Contributor Author

Please wait a bit, looks win32-darkmodelib has too many codes (main branch 1M lines, old win32-darkmode only has hundred lines).

D:\Libs\win32-darkmodelib\src>perl d:\Dev\MSYS2\opt\bin\cloc.pl .
      27 text files.
      27 unique files.
       0 files ignored.

github.com/AlDanial/cloc v 2.08  T=0.08 s (322.6 files/s, 164987.9 lines/s)
---------------------------------------------------------------------------------------
Language                             files          blank        comment           code
---------------------------------------------------------------------------------------
C++                                     10           1264           3192           6641
C/C++ Header                            15            366            589           1532
Windows Module Definition                1              0              0            183
Windows Resource File                    1              2              4             34
---------------------------------------------------------------------------------------
SUM:                                    27           1632           3785           8390
---------------------------------------------------------------------------------------

I don't understand why it's need to subcalss all common controls.

Isn't the code 8k lines?

Those common controls won't render correctly in dark mode. Some part of the control will still rendering the way in light theme. E.g. buttons render as light, or some background render as light.

I didn't find a simple way to fix them without subclass them. In fact notepad++ also does the same way (subclass those controls).

@zufuliu

zufuliu commented Apr 9, 2026

Copy link
Copy Markdown
Owner

Isn't the code 8k lines?

It matters at least for matepath:

D:\notepad4\notepad4\matepath\src>perl d:\Dev\MSYS2\opt\bin\cloc.pl .
      20 text files.
      18 unique files.
       2 files ignored.

github.com/AlDanial/cloc v 2.08  T=0.09 s (200.3 files/s, 132208.7 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
C++                                  5           1343           1129           7268
C/C++ Header                        10            174            213           1090
Windows Resource File                1             58             61            540
DOS Batch                            2              0              0              6
-----------------------------------------------------------------------------------
SUM:                                18           1575           1403           8904
-----------------------------------------------------------------------------------

@lostindark

Copy link
Copy Markdown
Contributor Author

Isn't the code 8k lines?

It matters at least for matepath:

D:\notepad4\notepad4\matepath\src>perl d:\Dev\MSYS2\opt\bin\cloc.pl .
      20 text files.
      18 unique files.
       2 files ignored.

github.com/AlDanial/cloc v 2.08  T=0.09 s (200.3 files/s, 132208.7 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
C++                                  5           1343           1129           7268
C/C++ Header                        10            174            213           1090
Windows Resource File                1             58             61            540
DOS Batch                            2              0              0              6
-----------------------------------------------------------------------------------
SUM:                                18           1575           1403           8904
-----------------------------------------------------------------------------------

matepath is a different project right? Haven't looked into support darkmode on it yet.

@Matteo-Nigro

Copy link
Copy Markdown
Contributor

This is a long overdue feature, it would be nice to be able to implement it. 💪🏻
If with the Dark mod of the toolbar the icons are unclear let me know and I will update them or review them 🖌️

@zufuliu zufuliu modified the milestones: v26.05, v26.07 May 5, 2026
@Casonctin

Copy link
Copy Markdown

After testing, I found that the scroll bar is white and the save changes dialog.

image

lostindark added a commit to lostindark/notepad4 that referenced this pull request May 20, 2026
Address PR zufuliu#1203 feedback: scroll bars and the save-changes dialog were rendered in the light theme even when dark mode is active.

- Enable scroll bar fix in darkmodelib (mode 2: per-window) and rely on
  the existing enableDarkScrollBarForWindowAndChildren(hwndMain) call so
  the Scintilla edit window's scroll bars use the dark theme.
- Route Notepad4's MsgBox() through dmlib::darkMessageBoxW(), which
  renders message boxes as themed task dialogs when dark mode is on.
- Fix two upstream darkmodelib namespacing bugs that surface when
  _DARKMODELIB_USE_SCROLLBAR_FIX is defined (DmlibHook.cpp uses
  ModuleHandle / LoadFn without the dmlib_module:: prefix).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lostindark added a commit to lostindark/notepad4 that referenced this pull request May 21, 2026
Address PR zufuliu#1203 feedback: scroll bars and the save-changes dialog were rendered in the light theme even when dark mode is active.

- Enable scroll bar fix in darkmodelib (mode 2: per-window) and rely on
  the existing enableDarkScrollBarForWindowAndChildren(hwndMain) call so
  the Scintilla edit window's scroll bars use the dark theme.
- Route Notepad4's MsgBox() through dmlib::darkMessageBoxW(), which
  renders message boxes as themed task dialogs when dark mode is on.
- Fix two upstream darkmodelib namespacing bugs that surface when
  _DARKMODELIB_USE_SCROLLBAR_FIX is defined (DmlibHook.cpp uses
  ModuleHandle / LoadFn without the dmlib_module:: prefix).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lostindark added a commit to lostindark/notepad4 that referenced this pull request May 21, 2026
Address PR zufuliu#1203 feedback: scroll bars and the save-changes dialog were rendered in the light theme even when dark mode is active.

- Enable scroll bar fix in darkmodelib (mode 2: per-window) and rely on
  the existing enableDarkScrollBarForWindowAndChildren(hwndMain) call so
  the Scintilla edit window's scroll bars use the dark theme.
- Route Notepad4's MsgBox() through dmlib::darkMessageBoxW(), which
  renders message boxes as themed task dialogs when dark mode is on.
- Fix two upstream darkmodelib namespacing bugs that surface when
  _DARKMODELIB_USE_SCROLLBAR_FIX is defined (DmlibHook.cpp uses
  ModuleHandle / LoadFn without the dmlib_module:: prefix).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lostindark

Copy link
Copy Markdown
Contributor Author

After testing, I found that the scroll bar is white and the save changes dialog.

image

This should be fixed now.

@Casonctin

Copy link
Copy Markdown

After testing, I found that the scroll bar is white and the save changes dialog.
image

This should be fixed now.

Confirmed its fixed. Every dialog and popup is now in dark mode! Thank you!

@Matteo-Nigro

Copy link
Copy Markdown
Contributor

Great job, @lostindark it looks really nice now. Well done!
Just a quick note: the toolbars' button rollovers still use the old (light) style.
Unlike the menu bar, which uses the dark style for its rollovers.

Registrazione 2026-05-22 112219

@zufuliu zufuliu linked an issue May 23, 2026 that may be closed by this pull request
lostindark added a commit to lostindark/notepad4 that referenced this pull request May 23, 2026
Address PR zufuliu#1203 feedback: scroll bars and the save-changes dialog were rendered in the light theme even when dark mode is active.

- Enable scroll bar fix in darkmodelib (mode 2: per-window) and rely on
  the existing enableDarkScrollBarForWindowAndChildren(hwndMain) call so
  the Scintilla edit window's scroll bars use the dark theme.
- Route Notepad4's MsgBox() through dmlib::darkMessageBoxW(), which
  renders message boxes as themed task dialogs when dark mode is on.
- Fix two upstream darkmodelib namespacing bugs that surface when
  _DARKMODELIB_USE_SCROLLBAR_FIX is defined (DmlibHook.cpp uses
  ModuleHandle / LoadFn without the dmlib_module:: prefix).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lostindark added a commit to lostindark/notepad4 that referenced this pull request May 23, 2026
Address PR zufuliu#1203 feedback: scroll bars and the save-changes dialog were rendered in the light theme even when dark mode is active.

- Enable scroll bar fix in darkmodelib (mode 2: per-window) and rely on
  the existing enableDarkScrollBarForWindowAndChildren(hwndMain) call so
  the Scintilla edit window's scroll bars use the dark theme.
- Route Notepad4's MsgBox() through dmlib::darkMessageBoxW(), which
  renders message boxes as themed task dialogs when dark mode is on.
- Fix two upstream darkmodelib namespacing bugs that surface when
  _DARKMODELIB_USE_SCROLLBAR_FIX is defined (DmlibHook.cpp uses
  ModuleHandle / LoadFn without the dmlib_module:: prefix).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lostindark and others added 2 commits May 22, 2026 22:48
Vendor ozone10/win32-darkmodelib source files directly in darkmodelib/
to provide native Windows dark mode support for Notepad4's UI chrome,
tied to the existing Style Theme (Default/Dark) setting.

Features:
- Dark title bar, menu bar, context menus (via system dark mode APIs)
- Dark toolbar, rebar, status bar with darkmodelib subclassing
- Dark tooltips and scrollbars
- All dialogs automatically themed via WH_CALLWNDPROCRET hook on
  WM_INITDIALOG (no per-dialog-proc changes needed)
- Toolbar Customize dialog fixed with temporary SetSysColors override
- Custom color hierarchy for visual depth:
  Editor #1E1E1E / Dialogs #252526 / Toolbar #2D2D2D / Controls #383838
- View colors for list boxes, list views, tree views, and headers
- Theme switching via View > Style Theme toggles dark mode on/off
- WM_SETTINGCHANGE handled for system dark/light mode changes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Upstream win32-darkmodelib was updated with several commits including a
breaking rename:
- 9573105: DarkModeSubclass -> Darkmodelib, namespace DarkMode -> dmlib
- Multiple tab/up-down/combo polish commits
- Fix warnings, clang-tidy cleanup

Updates:
- Renamed darkmodelib/DarkModeSubclass.h/cpp -> Darkmodelib.h/cpp
- Updated src/DarkMode.cpp and src/Notepad4.cpp:
  - #include "DarkModeSubclass.h" -> #include "Darkmodelib.h"
  - DarkMode:: -> dmlib::
- Updated build/VisualStudio/Notepad4.vcxproj file references
- Refreshed all other darkmodelib files from upstream

MinGW Makefile uses wildcards so no makefile change needed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lostindark added a commit to lostindark/notepad4 that referenced this pull request May 23, 2026
Address PR zufuliu#1203 feedback: scroll bars and the save-changes dialog were rendered in the light theme even when dark mode is active.

- Enable scroll bar fix in darkmodelib (mode 2: per-window) and rely on
  the existing enableDarkScrollBarForWindowAndChildren(hwndMain) call so
  the Scintilla edit window's scroll bars use the dark theme.
- Route Notepad4's MsgBox() through dmlib::darkMessageBoxW(), which
  renders message boxes as themed task dialogs when dark mode is on.
- Fix two upstream darkmodelib namespacing bugs that surface when
  _DARKMODELIB_USE_SCROLLBAR_FIX is defined (DmlibHook.cpp uses
  ModuleHandle / LoadFn without the dmlib_module:: prefix).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address PR zufuliu#1203 feedback so that scroll bars, message boxes, the file
open/save dialog, and toolbar button rollovers all render correctly when
dark mode is toggled on or off.

- Enable per-window scroll bar fix in darkmodelib (mode 2) so the
  Scintilla edit window's scroll bars use the dark theme via the
  existing enableDarkScrollBarForWindowAndChildren(hwndMain) call.
- Route Notepad4's MsgBox() through dmlib::darkMessageBoxW(), which
  renders message boxes as themed task dialogs when dark mode is on.
- Broadcast WM_THEMECHANGED to hwndMain and all descendants after a
  theme switch so themed controls (including scroll bars) re-open
  their theme handles and pick up the new light/dark style.
- Gate the OpenNcThemeData IAT hook on IsDarkModeActive() so scroll
  bars revert to the light theme after switching back from dark.
- Gate the WM_INITDIALOG thread hook on isExperimentalActive() and
  on the dialog's HINSTANCE matching this app's module, so system
  dialogs hosted in our process (common file open/save, etc.) are
  left untouched.
- Subclass the main window with setWindowNotifyCustomDrawSubclass so
  darkmodelib can custom-draw toolbar buttons (dark hover/checked
  states) via the toolbar's NM_CUSTOMDRAW notifications, which the
  rebar forwards up to its parent. This matches Notepad++'s approach.
- Fix two upstream darkmodelib namespacing bugs that surface when
  _DARKMODELIB_USE_SCROLLBAR_FIX is defined (DmlibHook.cpp uses
  ModuleHandle / LoadFn without the dmlib_module:: prefix).
- Add missing #include <string_view> in DmlibHook.cpp so MinGW
  GCC/Clang builds compile (upstream pulls this in via StdAfx.h
  which we do not vendor).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lostindark

Copy link
Copy Markdown
Contributor Author

Great job, @lostindark it looks really nice now. Well done! Just a quick note: the toolbars' button rollovers still use the old (light) style. Unlike the menu bar, which uses the dark style for its rollovers.

Registrazione 2026-05-22 112219

Fixed in latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dark Mode

4 participants