|
10 | 10 |
|
11 | 11 | // Declared in Styles.cpp |
12 | 12 | extern int np2StyleTheme; |
| 13 | +// Declared in Notepad4.cpp - this app's module handle |
| 14 | +extern HINSTANCE g_hInstance; |
13 | 15 |
|
14 | 16 | // Thread-level hook to intercept WM_INITDIALOG and apply dark mode to dialogs |
15 | 17 | static HHOOK s_hCallWndProcRetHook = nullptr; |
16 | 18 |
|
17 | 19 | static LRESULT CALLBACK DarkMode_CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam) noexcept { |
18 | 20 | if (nCode == HC_ACTION) { |
19 | 21 | const CWPRETSTRUCT *cwpret = reinterpret_cast<const CWPRETSTRUCT *>(lParam); |
20 | | - if (cwpret->message == WM_INITDIALOG) { |
| 22 | + // Only theme dialogs created by this app while dark mode is active. |
| 23 | + // This avoids touching system dialogs (e.g. the common file open/save |
| 24 | + // dialog) that are hosted in our process but owned by comdlg32/shell. |
| 25 | + if (cwpret->message == WM_INITDIALOG |
| 26 | + && dmlib::isExperimentalActive() |
| 27 | + && reinterpret_cast<HINSTANCE>(GetWindowLongPtr(cwpret->hwnd, GWLP_HINSTANCE)) == g_hInstance) { |
21 | 28 | DarkMode_ApplyToDialog(cwpret->hwnd); |
22 | 29 | } |
23 | 30 | } |
@@ -113,10 +120,36 @@ void DarkMode_OnThemeChanged(int newTheme) noexcept { |
113 | 120 | } |
114 | 121 | } |
115 | 122 |
|
| 123 | +// Broadcast WM_THEMECHANGED to a window and all its descendants so that |
| 124 | +// themed controls (including scroll bars) re-open their theme handles. |
| 125 | +static BOOL CALLBACK DarkMode_SendThemeChangedProc(HWND hwnd, LPARAM /*lParam*/) noexcept { |
| 126 | + SendMessage(hwnd, WM_THEMECHANGED, 0, 0); |
| 127 | + return TRUE; |
| 128 | +} |
| 129 | + |
| 130 | +void DarkMode_BroadcastThemeChanged(HWND hwnd) noexcept { |
| 131 | + if (hwnd == nullptr) { |
| 132 | + return; |
| 133 | + } |
| 134 | + SendMessage(hwnd, WM_THEMECHANGED, 0, 0); |
| 135 | + EnumChildWindows(hwnd, DarkMode_SendThemeChangedProc, 0); |
| 136 | +} |
| 137 | + |
116 | 138 | bool DarkMode_HandleSettingChange([[maybe_unused]] HWND hwnd, LPARAM lParam) noexcept { |
117 | 139 | return dmlib::handleSettingChange(lParam); |
118 | 140 | } |
119 | 141 |
|
120 | 142 | bool DarkMode_IsEnabled() noexcept { |
121 | 143 | return dmlib::isExperimentalActive(); |
122 | 144 | } |
| 145 | + |
| 146 | +int DarkMode_MessageBox(HWND hwnd, LPCWSTR text, LPCWSTR caption, UINT uType, WORD wLanguageId) noexcept { |
| 147 | + if (dmlib::isExperimentalActive()) { |
| 148 | + const HRESULT hr = dmlib::darkMessageBoxW(hwnd, text, caption, uType); |
| 149 | + if (hr > 0) { |
| 150 | + return static_cast<int>(hr); |
| 151 | + } |
| 152 | + // Fall through to MessageBoxEx on failure. |
| 153 | + } |
| 154 | + return MessageBoxEx(hwnd, text, caption, uType, wLanguageId); |
| 155 | +} |
0 commit comments