@@ -453,13 +453,82 @@ namespace DarkMode
453453
454454 Theme tDefault (darkCustomizedColors);
455455
456+ static ColorsView darkColorsView{
457+ RGB (41 , 49 , 52 ), // background
458+ RGB (224 , 226 , 228 ), // text
459+ RGB (100 , 100 , 100 ) // gridlines
460+ };
461+
462+ static ColorsView lightColorsView{
463+ RGB (255 , 255 , 255 ), // background
464+ RGB (0 , 0 , 0 ), // text
465+ RGB (240 , 240 , 240 ) // gridlines
466+ };
467+
456468 static Theme& getTheme ()
457469 {
458470 return tDefault;
459471 }
460472
461- static COLORREF g_bgColor = RGB (41 , 49 , 52 );
462- static COLORREF g_fgColor = RGB (224 , 226 , 228 );
473+ struct BrushesView
474+ {
475+ HBRUSH background = nullptr ;
476+ HBRUSH gridlines = nullptr ;
477+
478+ BrushesView (const ColorsView& colors)
479+ : background(::CreateSolidBrush(colors.background))
480+ , gridlines(::CreateSolidBrush(colors.gridlines))
481+ {}
482+
483+ ~BrushesView ()
484+ {
485+ ::DeleteObject (background); background = nullptr ;
486+ ::DeleteObject (gridlines); gridlines = nullptr ;
487+ }
488+
489+ void change (const ColorsView& colors)
490+ {
491+ ::DeleteObject (background);
492+ ::DeleteObject (gridlines);
493+
494+ background = ::CreateSolidBrush (colors.background );
495+ gridlines = ::CreateSolidBrush (colors.gridlines );
496+ }
497+ };
498+
499+ struct ThemeView
500+ {
501+ ColorsView _clrView;
502+ BrushesView _hbrView;
503+
504+ ThemeView ()
505+ : _clrView({ RGB (41 , 49 , 52 ), RGB (224 , 226 , 228 ), RGB (100 , 100 , 100 ) })
506+ , _hbrView(_clrView)
507+ {}
508+
509+ ThemeView (const ColorsView& colorsView)
510+ : _clrView(colorsView)
511+ , _hbrView(_clrView)
512+ {}
513+
514+ void updateBrushes ()
515+ {
516+ _hbrView.change (_clrView);
517+ }
518+
519+ void change (ColorsView colors)
520+ {
521+ _clrView = colors;
522+ updateBrushes ();
523+ }
524+ };
525+
526+ static ThemeView tView{darkColorsView};
527+
528+ static ThemeView& getThemeView ()
529+ {
530+ return tView;
531+ }
463532
464533 static bool g_useDarkMode = true ;
465534 static bool g_enableWindowsMode = false ;
@@ -506,18 +575,17 @@ namespace DarkMode
506575
507576 DarkMode::setDarkCustomColors (static_cast <DarkMode::ColorTone>(tone));
508577 DarkMode::getTheme ()._colors = DarkMode::darkCustomizedColors;
509- g_bgColor = RGB (41 , 49 , 52 );
510- g_fgColor = RGB (224 , 226 , 228 );
578+ DarkMode::getThemeView ()._clrView = DarkMode::darkColorsView;
511579 }
512580 else
513581 {
514582 DarkMode::getTheme ()._colors = DarkMode::lightColors;
515- g_bgColor = RGB (255 , 255 , 255 );
516- g_fgColor = RGB (0 , 0 , 0 );
583+ DarkMode::getThemeView ()._clrView = DarkMode::lightColorsView;
517584 }
518585
519- setClrFromIni (sectionColorsView, L" backgroundView" , iniPath, &DarkMode::g_bgColor);
520- setClrFromIni (sectionColorsView, L" textView" , iniPath, &DarkMode::g_fgColor);
586+ setClrFromIni (sectionColorsView, L" backgroundView" , iniPath, &DarkMode::getThemeView ()._clrView .background );
587+ setClrFromIni (sectionColorsView, L" textView" , iniPath, &DarkMode::getThemeView ()._clrView .text );
588+ setClrFromIni (sectionColorsView, L" gridlines" , iniPath, &DarkMode::getThemeView ()._clrView .gridlines );
521589
522590 setClrFromIni (sectionColors, L" background" , iniPath, &DarkMode::getTheme ()._colors .background );
523591 setClrFromIni (sectionColors, L" backgroundInteractive" , iniPath, &DarkMode::getTheme ()._colors .softerBackground );
@@ -536,6 +604,8 @@ namespace DarkMode
536604
537605 DarkMode::getTheme ()._brushes .change (DarkMode::getTheme ()._colors );
538606 DarkMode::getTheme ()._pens .change (DarkMode::getTheme ()._colors );
607+
608+ DarkMode::getThemeView ().updateBrushes ();
539609 }
540610 }
541611
@@ -600,7 +670,7 @@ namespace DarkMode
600670 }
601671
602672 static TreeViewStyle g_treeViewStyle = TreeViewStyle::classic;
603- static COLORREF g_treeViewBg = g_bgColor ;
673+ static COLORREF g_treeViewBg = RGB ( 41 , 49 , 52 ) ;
604674 static double g_lightnessTreeView = 50.0 ;
605675
606676 // adapted from https://stackoverflow.com/a/56678483
@@ -656,6 +726,12 @@ namespace DarkMode
656726 tDefault.change (colors);
657727 }
658728
729+ COLORREF getViewBackgroundColor () { return DarkMode::getThemeView ()._clrView .background ; }
730+ COLORREF getViewTextColor () { return DarkMode::getThemeView ()._clrView .text ; }
731+ COLORREF getViewGridlinesColor () { return DarkMode::getThemeView ()._clrView .gridlines ; }
732+ HBRUSH getViewBackgroundBrush () { return DarkMode::getThemeView ()._hbrView .background ; }
733+ HBRUSH getViewGridlinesBrush () { return DarkMode::getThemeView ()._hbrView .gridlines ; }
734+
659735 bool handleSettingChange (LPARAM lParam)
660736 {
661737 if (DarkMode::isExperimentalSupported () && IsColorSchemeChangeMessage (lParam))
@@ -1138,11 +1214,11 @@ namespace DarkMode
11381214 {
11391215 if (hdcFrom)
11401216 {
1141- renderButton (hWnd, hdcFrom, buttonData.hTheme , iPartID, buttonData.iStateID );
1217+ DarkMode:: renderButton (hWnd, hdcFrom, buttonData.hTheme , iPartID, buttonData.iStateID );
11421218 }
11431219 if (hdcTo)
11441220 {
1145- renderButton (hWnd, hdcTo, buttonData.hTheme , iPartID, iStateID);
1221+ DarkMode:: renderButton (hWnd, hdcTo, buttonData.hTheme , iPartID, iStateID);
11461222 }
11471223
11481224 buttonData.iStateID = iStateID;
@@ -1151,7 +1227,7 @@ namespace DarkMode
11511227 }
11521228 else
11531229 {
1154- renderButton (hWnd, hdc, buttonData.hTheme , iPartID, iStateID);
1230+ DarkMode:: renderButton (hWnd, hdc, buttonData.hTheme , iPartID, iStateID);
11551231
11561232 buttonData.iStateID = iStateID;
11571233 }
@@ -1168,8 +1244,6 @@ namespace DarkMode
11681244 DWORD_PTR dwRefData
11691245 )
11701246 {
1171- UNREFERENCED_PARAMETER (uIdSubclass);
1172-
11731247 auto pButtonData = reinterpret_cast <ButtonData*>(dwRefData);
11741248
11751249 switch (uMsg)
@@ -1185,7 +1259,7 @@ namespace DarkMode
11851259
11861260 case WM_NCDESTROY:
11871261 {
1188- ::RemoveWindowSubclass (hWnd, ButtonSubclass, g_buttonSubclassID );
1262+ ::RemoveWindowSubclass (hWnd, ButtonSubclass, uIdSubclass );
11891263 delete pButtonData;
11901264 break ;
11911265 }
@@ -1223,7 +1297,7 @@ namespace DarkMode
12231297 hdc = ::BeginPaint (hWnd, &ps);
12241298 }
12251299
1226- paintButton (hWnd, hdc, *pButtonData);
1300+ DarkMode:: paintButton (hWnd, hdc, *pButtonData);
12271301
12281302 if (ps.hdc )
12291303 {
@@ -1248,7 +1322,7 @@ namespace DarkMode
12481322 {
12491323 // skip the button's normal wndproc so it won't redraw out of wm_paint
12501324 LRESULT lr = DefWindowProc (hWnd, uMsg, wParam, lParam);
1251- InvalidateRect (hWnd, nullptr , FALSE );
1325+ :: InvalidateRect (hWnd, nullptr , FALSE );
12521326 return lr;
12531327 }
12541328 break ;
@@ -1414,7 +1488,7 @@ namespace DarkMode
14141488 hdc = ::BeginPaint (hWnd, &ps);
14151489 }
14161490
1417- paintGroupbox (hWnd, hdc, *pButtonData);
1491+ DarkMode:: paintGroupbox (hWnd, hdc, *pButtonData);
14181492
14191493 if (ps.hdc )
14201494 {
@@ -1553,7 +1627,7 @@ namespace DarkMode
15531627
15541628 ::FrameRect (hdc, &rcFrame, DarkMode::getEdgeBrush());
15551629
1556- DrawText (hdc, label, -1 , &rcText, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
1630+ :: DrawText (hdc, label, -1 , &rcText, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
15571631
15581632 ::DeleteObject (hClip);
15591633
@@ -2415,7 +2489,7 @@ namespace DarkMode
24152489
24162490 RECT rc{};
24172491 ::GetClientRect (hWnd, &rc);
2418- ::FillRect (( HDC) wParam, &rc, DarkMode::getBackgroundBrush());
2492+ ::FillRect (reinterpret_cast < HDC>( wParam) , &rc, DarkMode::getBackgroundBrush());
24192493 return TRUE ;
24202494 }
24212495
@@ -2456,7 +2530,7 @@ namespace DarkMode
24562530 RECT rcPart{};
24572531 SendMessage (hWnd, SB_GETRECT, i, reinterpret_cast <LPARAM>(&rcPart));
24582532 RECT rcIntersect{};
2459- if (! ::IntersectRect (&rcIntersect, &rcPart, &ps.rcPaint ))
2533+ if (::IntersectRect (&rcIntersect, &rcPart, &ps.rcPaint ) == 0 )
24602534 {
24612535 continue ;
24622536 }
@@ -2504,7 +2578,7 @@ namespace DarkMode
25042578 , static_cast <ULONG_PTR>(lr)
25052579 };
25062580
2507- SendMessage (::GetParent (hWnd), WM_DRAWITEM, id, ( LPARAM) &dis);
2581+ SendMessage (::GetParent (hWnd), WM_DRAWITEM, id, reinterpret_cast < LPARAM>( &dis) );
25082582 }
25092583 else
25102584 {
@@ -2945,9 +3019,9 @@ namespace DarkMode
29453019 DarkMode::setDarkTooltips (hWnd, DarkMode::ToolTipsType::listview);
29463020 }
29473021
2948- ListView_SetTextColor (hWnd, g_fgColor );
2949- ListView_SetTextBkColor (hWnd, g_bgColor );
2950- ListView_SetBkColor (hWnd, g_bgColor );
3022+ ListView_SetTextColor (hWnd, DarkMode::getViewTextColor () );
3023+ ListView_SetTextBkColor (hWnd, DarkMode::getViewBackgroundColor () );
3024+ ListView_SetBkColor (hWnd, DarkMode::getViewBackgroundColor () );
29513025
29523026 if (p._subclass )
29533027 {
@@ -2959,8 +3033,8 @@ namespace DarkMode
29593033
29603034 void themeTreeView (HWND hWnd, DarkModeParams p)
29613035 {
2962- TreeView_SetTextColor (hWnd, g_fgColor );
2963- TreeView_SetBkColor (hWnd, g_bgColor );
3036+ TreeView_SetTextColor (hWnd, DarkMode::getViewTextColor () );
3037+ TreeView_SetBkColor (hWnd, DarkMode::getViewBackgroundColor () );
29643038
29653039 // DarkMode::calculateTreeViewStyle();
29663040 DarkMode::setTreeViewStyle (hWnd);
@@ -3141,11 +3215,9 @@ namespace DarkMode
31413215 }
31423216 }
31433217 }
3144- else if (DarkMode::isThemeDark () && hasGridlines)
3218+ else if (hasGridlines)
31453219 {
3146- HBRUSH hbrDarkTheme = ::CreateSolidBrush (g_bgColor);
3147- ::FillRect (lplvcd->nmcd.hdc, &lplvcd->nmcd.rc, hbrDarkTheme);
3148- ::DeleteObject (hbrDarkTheme);
3220+ ::FillRect (lplvcd->nmcd.hdc, &lplvcd->nmcd.rc, DarkMode::getViewBackgroundBrush());
31493221 }
31503222 }
31513223
@@ -3162,7 +3234,7 @@ namespace DarkMode
31623234 static void drawGridlines (LPNMLVCUSTOMDRAW& lplvcd)
31633235 {
31643236 HWND& hList = lplvcd->nmcd .hdr .hwndFrom ;
3165- const HBRUSH& hBrush = DarkMode::getEdgeBrush ();
3237+ const HBRUSH& hBrush = DarkMode::getViewGridlinesBrush ();
31663238
31673239 HWND hHeader = ListView_GetHeader (hList);
31683240 RECT rcHeader{};
@@ -3178,10 +3250,6 @@ namespace DarkMode
31783250 , lplvcd->nmcd .rc .bottom
31793251 };
31803252
3181- HBRUSH hbrDarkTheme = nullptr ;
3182- if (DarkMode::isThemeDark ())
3183- hbrDarkTheme = ::CreateSolidBrush (g_bgColor);
3184-
31853253 const int iLastItem = ListView_GetItemCount (hList);
31863254
31873255 LVITEMINDEX lvii{ iLastItem, 0 };
@@ -3195,31 +3263,19 @@ namespace DarkMode
31953263
31963264 ::FillRect (lplvcd->nmcd.hdc, &rcGridline, hBrush);
31973265
3198- if (hbrDarkTheme != nullptr )
3199- {
3200- rcGridline.top = rcGridlineTmp.top ;
3201- ::OffsetRect (&rcGridline, -2 , 0 );
3202- ::FillRect (lplvcd->nmcd.hdc, &rcGridline, hbrDarkTheme);
3203- rcGridline.top = rcHeader.bottom ;
3204- }
3266+ rcGridline.top = rcGridlineTmp.top ;
3267+ ::OffsetRect (&rcGridline, DarkMode::isThemeDark() ? -2 : -1, 0);
3268+ ::FillRect (lplvcd->nmcd.hdc, &rcGridline, DarkMode::getViewBackgroundBrush());
3269+ rcGridline.top = rcHeader.bottom ;
32053270 }
32063271
32073272 rcGridline.left = rcGridlineTmp.right ;
32083273 rcGridline.right = rcGridline.left + wGrid;
32093274 ::FillRect (lplvcd->nmcd.hdc, &rcGridline, hBrush);
32103275
3211- if (hbrDarkTheme != nullptr )
3212- {
3213- rcGridline.top = rcGridlineTmp.top ;
3214- ::OffsetRect (&rcGridline, -2 , 0 );
3215- ::FillRect (lplvcd->nmcd.hdc, &rcGridline, hbrDarkTheme);
3216- }
3217-
3218- if (hbrDarkTheme != nullptr )
3219- {
3220- ::DeleteObject (hbrDarkTheme);
3221- hbrDarkTheme= nullptr ;
3222- }
3276+ rcGridline.top = rcGridlineTmp.top ;
3277+ ::OffsetRect (&rcGridline, DarkMode::isThemeDark() ? -2 : -1, 0);
3278+ ::FillRect (lplvcd->nmcd.hdc, &rcGridline, DarkMode::getViewBackgroundBrush());
32233279
32243280 rcGridline = lplvcd->nmcd .rc ;
32253281 RECT rcItem{};
@@ -3750,7 +3806,7 @@ namespace DarkMode
37503806
37513807 void calculateTreeViewStyle ()
37523808 {
3753- COLORREF bgColor = g_bgColor ;
3809+ COLORREF bgColor = DarkMode::getViewBackgroundColor () ;
37543810
37553811 if (g_treeViewBg != bgColor || g_lightnessTreeView == 50.0 )
37563812 {
0 commit comments