@@ -72,8 +72,26 @@ class CWebWindow
72
72
return result;
73
73
}
74
74
75
- m_webviewController->put_ZoomFactor (zoom);
75
+ auto webView2_13 = m_webview.try_query <ICoreWebView2_13>();
76
+ if (webView2_13)
77
+ {
78
+ wil::com_ptr<ICoreWebView2Profile> webView2Profile;
79
+ webView2_13->get_Profile (&webView2Profile);
80
+ if (webView2Profile)
81
+ {
82
+ auto webView2Profile2 = webView2Profile.try_query <ICoreWebView2Profile2>();
83
+ webView2Profile2->put_PreferredColorScheme (
84
+ m_parent->m_bDarkBackgroundEnabled ? COREWEBVIEW2_PREFERRED_COLOR_SCHEME_DARK : COREWEBVIEW2_PREFERRED_COLOR_SCHEME_LIGHT);
85
+ }
86
+ }
76
87
88
+ wil::com_ptr<ICoreWebView2Controller2> controller2 = m_webviewController.query <ICoreWebView2Controller2>();
89
+ if (controller2)
90
+ {
91
+ const COREWEBVIEW2_COLOR bg = { 255 , 255 , 255 , 255 };
92
+ controller2->put_DefaultBackgroundColor (bg);
93
+ }
94
+ m_webviewController->put_ZoomFactor (zoom);
77
95
m_webviewController->add_AcceleratorKeyPressed (
78
96
Callback<ICoreWebView2AcceleratorKeyPressedEventHandler>(
79
97
[this ](ICoreWebView2Controller* sender, ICoreWebView2AcceleratorKeyPressedEventArgs* args) {
@@ -268,12 +286,13 @@ class CWebWindow
268
286
}
269
287
270
288
HRESULT Create (IWebDiffWindow* pDiffWindow, HINSTANCE hInstance, HWND hWndParent, const wchar_t * url, const wchar_t * userDataFolder,
271
- const SIZE& size, bool fitToWindow, double zoom, std::wstring& userAgent,
289
+ const SIZE& size, bool fitToWindow, double zoom, bool darkBackgroundEnabled, std::wstring& userAgent,
272
290
IWebDiffCallback* callback, std::function<void (WebDiffEvent::EVENT_TYPE, IUnknown*, IUnknown*)> eventHandler)
273
291
{
274
292
m_pDiffWindow = pDiffWindow;
275
293
m_fitToWindow = fitToWindow;
276
294
m_size = size;
295
+ m_bDarkBackgroundEnabled = darkBackgroundEnabled;
277
296
m_eventHandler = eventHandler;
278
297
MyRegisterClass (hInstance);
279
298
m_hWnd = CreateWindowExW (0 , L" WinWebWindowClass" , nullptr ,
@@ -1357,6 +1376,20 @@ class CWebWindow
1357
1376
return m_webmessage;
1358
1377
}
1359
1378
1379
+ bool IsDarkBackgroundEnabled () const
1380
+ {
1381
+ return m_bDarkBackgroundEnabled;
1382
+ }
1383
+
1384
+ void SetDarkBackgroundEnabled (bool enabled)
1385
+ {
1386
+ m_bDarkBackgroundEnabled = enabled;
1387
+ DeleteObject (s_hbrBackground);
1388
+ s_hbrBackground = CreateSolidBrush (m_bDarkBackgroundEnabled ? RGB (40 , 40 , 60 ) : RGB (206 , 215 , 230 ));
1389
+ SetClassLongPtr (m_hWebViewParent, GCLP_HBRBACKGROUND, (LONG_PTR)s_hbrBackground);
1390
+ InvalidateRect (m_hWebViewParent, NULL , TRUE );
1391
+ }
1392
+
1360
1393
private:
1361
1394
1362
1395
HRESULT InitializeWebView (const wchar_t * url, double zoom, const std::wstring& userAgent, const wchar_t * userDataFolder, IWebDiffCallback* callback)
@@ -1661,7 +1694,7 @@ class CWebWindow
1661
1694
wcex.cbWndExtra = 0 ;
1662
1695
wcex.hInstance = hInstance;
1663
1696
wcex.hCursor = LoadCursor (nullptr , IDC_ARROW);
1664
- wcex.hbrBackground = CreateSolidBrush ( RGB ( 206 , 215 , 230 )) ;
1697
+ wcex.hbrBackground = s_hbrBackground ;
1665
1698
wcex.lpszClassName = L" WebViewParentClass" ;
1666
1699
}
1667
1700
return RegisterClassExW (&wcex) != 0 ;
@@ -2083,6 +2116,7 @@ class CWebWindow
2083
2116
HWND m_hWebViewParent = nullptr ;
2084
2117
HFONT m_hToolbarFont = nullptr ;
2085
2118
HFONT m_hEditFont = nullptr ;
2119
+ inline static HBRUSH s_hbrBackground = CreateSolidBrush(RGB(206 , 215 , 230 ));
2086
2120
WNDPROC m_oldTabCtrlWndProc = nullptr ;
2087
2121
WNDPROC m_oldEditWndProc = nullptr ;
2088
2122
TOOLINFO m_toolItem{};
@@ -2097,6 +2131,7 @@ class CWebWindow
2097
2131
std::wstring m_currentUrl;
2098
2132
std::wstring m_toolTipText = L" test" ;
2099
2133
bool m_showToolTip = false ;
2134
+ bool m_bDarkBackgroundEnabled = false ;
2100
2135
std::wstring m_webmessage;
2101
2136
inline static const auto GetDpiForWindowFunc = []() {
2102
2137
HMODULE hUser32 = GetModuleHandle (L" user32.dll" );
0 commit comments