@@ -12,13 +12,10 @@ class CWebDiffWindow : public IWebDiffWindow
1212public:
1313 CWebDiffWindow ()
1414 {
15- s_hbrBackground = CreateSolidBrush (m_bDarkBackgroundEnabled ? RGB (0 , 0 , 0 ) : GetSysColor (COLOR_3DFACE));
1615 }
1716
1817 ~CWebDiffWindow ()
1918 {
20- if (s_hbrBackground)
21- DeleteObject (s_hbrBackground);
2219 }
2320
2421 bool Create (HINSTANCE hInstance, HWND hWndParent, int nID, const RECT& rc)
@@ -92,7 +89,7 @@ class CWebDiffWindow : public IWebDiffWindow
9289 std::wstring userDataFolder = GetUserDataFolderPath (i);
9390 ComPtr<IWebDiffCallback> callback2 (callback);
9491 hr = m_webWindow[i].Create (this , m_hInstance, m_hWnd, urls[i], userDataFolder.c_str (),
95- m_size, m_fitToWindow, m_zoom, m_bDarkBackgroundEnabled , m_userAgent, nullptr ,
92+ m_size, m_fitToWindow, m_zoom, s_bDarkBackgroundEnabled , m_userAgent, nullptr ,
9693 [this , i, callback2](WebDiffEvent::EVENT_TYPE event, IUnknown* sender, IUnknown* args)
9794 {
9895 WebDiffEvent ev{};
@@ -442,20 +439,22 @@ class CWebDiffWindow : public IWebDiffWindow
442439
443440 bool IsDarkBackgroundEnabled () const
444441 {
445- return m_bDarkBackgroundEnabled ;
442+ return s_bDarkBackgroundEnabled ;
446443 }
447444
448445 void SetDarkBackgroundEnabled (bool enabled)
449446 {
450- m_bDarkBackgroundEnabled = enabled;
447+ if (s_bDarkBackgroundEnabled == enabled)
448+ return ;
449+ s_bDarkBackgroundEnabled = enabled;
450+ DeleteObject (s_hbrBackground);
451+ s_hbrBackground = CreateSolidBrush (s_bDarkBackgroundEnabled ? RGB (0 , 0 , 0 ) : GetSysColor (COLOR_3DFACE));
451452 if (m_hWnd)
452453 {
453- for (int pane = 0 ; pane < m_nPanes; ++pane)
454- m_webWindow[pane].SetDarkBackgroundEnabled (m_bDarkBackgroundEnabled);
455- DeleteObject (s_hbrBackground);
456- s_hbrBackground = CreateSolidBrush (m_bDarkBackgroundEnabled ? RGB (0 , 0 , 0 ) : GetSysColor (COLOR_3DFACE));
457454 SetClassLongPtr (m_hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)s_hbrBackground);
458455 InvalidateRect (m_hWnd, NULL , TRUE );
456+ for (int pane = 0 ; pane < m_nPanes; ++pane)
457+ m_webWindow[pane].SetDarkBackgroundEnabled (s_bDarkBackgroundEnabled);
459458 }
460459 }
461460
@@ -1544,7 +1543,7 @@ class CWebDiffWindow : public IWebDiffWindow
15441543 int m_nPanes = 0 ;
15451544 HWND m_hWnd = nullptr ;
15461545 HINSTANCE m_hInstance = nullptr ;
1547- HBRUSH s_hbrBackground = nullptr ;
1546+ inline static HBRUSH s_hbrBackground = CreateSolidBrush(GetSysColor(COLOR_3DFACE)) ;
15481547 CWebWindow m_webWindow[3 ];
15491548 int m_nDraggingSplitter = -1 ;
15501549 bool m_bHorizontalSplit = false ;
@@ -1562,7 +1561,7 @@ class CWebDiffWindow : public IWebDiffWindow
15621561 std::vector<DiffInfo> m_diffInfos;
15631562 DiffLocation m_diffLocation[3 ];
15641563 DiffOptions m_diffOptions{};
1565- bool m_bDarkBackgroundEnabled ;
1564+ inline static bool s_bDarkBackgroundEnabled = false ;
15661565 bool m_bShowDifferences = true ;
15671566 bool m_bShowWordDifferences = true ;
15681567 bool m_bSynchronizeEvents = true ;
0 commit comments