Skip to content

Commit ccb6ce0

Browse files
lostindarkCopilot
andcommitted
Dark mode: themed message boxes and dark scrollbars
Address PR #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>
1 parent 58bf4e2 commit ccb6ce0

6 files changed

Lines changed: 21 additions & 5 deletions

File tree

build/VisualStudio/Notepad4.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
<ItemDefinitionGroup>
159159
<ClCompile>
160160
<AdditionalIncludeDirectories>..\..\scintilla\include;..\..\scintilla\lexlib;..\..\scintilla\src;..\..\src;..\..\darkmodelib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
161-
<PreprocessorDefinitions>_WINDOWS;NOMINMAX;WIN32_LEAN_AND_MEAN;STRICT_TYPED_ITEMIDS;BOOST_REGEX_STANDALONE;NO_CXX11_REGEX;UNICODE;_UNICODE;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_DARKMODELIB_NO_INI_CONFIG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
161+
<PreprocessorDefinitions>_WINDOWS;NOMINMAX;WIN32_LEAN_AND_MEAN;STRICT_TYPED_ITEMIDS;BOOST_REGEX_STANDALONE;NO_CXX11_REGEX;UNICODE;_UNICODE;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_DARKMODELIB_NO_INI_CONFIG;_DARKMODELIB_USE_SCROLLBAR_FIX=2;%(PreprocessorDefinitions)</PreprocessorDefinitions>
162162
<WarningLevel>Level4</WarningLevel>
163163
<LanguageStandard>stdcpplatest</LanguageStandard>
164164
<LanguageStandard_C>stdc17</LanguageStandard_C>

build/mingw/notepad4.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ INCDIR = \
1414
-I"$(scintilla_dir)/include" \
1515
-I"$(darkmodelib_dir)"
1616

17-
CPPFLAGS += -D_DARKMODELIB_NO_INI_CONFIG
17+
CPPFLAGS += -D_DARKMODELIB_NO_INI_CONFIG -D_DARKMODELIB_USE_SCROLLBAR_FIX=2
1818

1919
LDFLAGS += -L"$(BINFOLDER)/obj"
2020

darkmodelib/DmlibHook.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static fnOpenNcThemeData pfOpenNcThemeData = nullptr;
168168

169169
bool dmlib_hook::loadOpenNcThemeData(const HMODULE& hUxtheme) noexcept
170170
{
171-
return LoadFn(hUxtheme, pfOpenNcThemeData, 49);
171+
return dmlib_module::LoadFn(hUxtheme, pfOpenNcThemeData, 49);
172172
}
173173

174174
#if defined(_DARKMODELIB_USE_SCROLLBAR_FIX) && (_DARKMODELIB_USE_SCROLLBAR_FIX > 1)
@@ -229,7 +229,7 @@ static HTHEME WINAPI MyOpenNcThemeData(HWND hWnd, LPCWSTR pszClassList)
229229

230230
void dmlib_hook::fixDarkScrollBar()
231231
{
232-
const ModuleHandle moduleComctl(L"comctl32.dll");
232+
const dmlib_module::ModuleHandle moduleComctl(L"comctl32.dll");
233233
if (moduleComctl.isLoaded())
234234
{
235235
auto* addr = iat_hook::FindDelayLoadThunkInModule(moduleComctl.get(), "uxtheme.dll", 49); // OpenNcThemeData

src/DarkMode.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,14 @@ bool DarkMode_HandleSettingChange([[maybe_unused]] HWND hwnd, LPARAM lParam) noe
120120
bool DarkMode_IsEnabled() noexcept {
121121
return dmlib::isExperimentalActive();
122122
}
123+
124+
int DarkMode_MessageBox(HWND hwnd, LPCWSTR text, LPCWSTR caption, UINT uType, WORD wLanguageId) noexcept {
125+
if (dmlib::isExperimentalActive()) {
126+
const HRESULT hr = dmlib::darkMessageBoxW(hwnd, text, caption, uType);
127+
if (hr > 0) {
128+
return static_cast<int>(hr);
129+
}
130+
// Fall through to MessageBoxEx on failure.
131+
}
132+
return MessageBoxEx(hwnd, text, caption, uType, wLanguageId);
133+
}

src/DarkMode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ bool DarkMode_HandleSettingChange(HWND hwnd, LPARAM lParam) noexcept;
2828

2929
// Check if dark mode UI is currently active.
3030
bool DarkMode_IsEnabled() noexcept;
31+
32+
// Show a message box that respects dark mode (uses Task Dialog when dark mode is active).
33+
// Returns the same kind of value as MessageBoxEx (IDOK, IDYES, IDNO, IDCANCEL, ...).
34+
int DarkMode_MessageBox(HWND hwnd, LPCWSTR text, LPCWSTR caption, UINT uType, WORD wLanguageId) noexcept;

src/Dialogs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Styles.h"
3535
#include "Dlapi.h"
3636
#include "Dialogs.h"
37+
#include "DarkMode.h"
3738
#include "resource.h"
3839
#include "Version.h"
3940

@@ -114,7 +115,7 @@ int MsgBox(UINT uType, UINT uIdMsg, ...) noexcept {
114115

115116
HWND hwnd = GetMsgBoxParent();
116117
PostMessage(hwndMain, APPM_CENTER_MESSAGE_BOX, AsInteger<WPARAM>(hwnd), 0);
117-
return MessageBoxEx(hwnd, szText, szTitle, uType, lang);
118+
return DarkMode_MessageBox(hwnd, szText, szTitle, uType, lang);
118119
}
119120

120121
//=============================================================================

0 commit comments

Comments
 (0)