From 17a51323a51aea7058aa6aa03ec806827916c86a Mon Sep 17 00:00:00 2001 From: krlvm <51774833+krlvm@users.noreply.github.com> Date: Tue, 8 Aug 2023 00:52:39 +0300 Subject: [PATCH] Little refactoring & optimizations --- AccentColorizer/AccentColorHelper.cpp | 10 +- AccentColorizer/AccentColorHelper.h | 3 +- AccentColorizer/BitmapHelper.cpp | 43 +-- AccentColorizer/BitmapHelper.h | 5 +- AccentColorizer/ColorHelper.cpp | 25 +- AccentColorizer/ColorHelper.h | 26 +- AccentColorizer/SettingsHelper.cpp | 1 + AccentColorizer/StyleModifier.cpp | 532 ++++++++++++++++++++------ AccentColorizer/StyleModifier.h | 2 +- AccentColorizer/SysColorsModifier.cpp | 21 +- AccentColorizer/SysColorsModifier.h | 2 +- AccentColorizer/main.cpp | 10 +- 12 files changed, 491 insertions(+), 189 deletions(-) diff --git a/AccentColorizer/AccentColorHelper.cpp b/AccentColorizer/AccentColorHelper.cpp index f10de15..83936e6 100644 --- a/AccentColorizer/AccentColorHelper.cpp +++ b/AccentColorizer/AccentColorHelper.cpp @@ -2,15 +2,16 @@ #include "ColorHelper.h" COLORREF g_dwAccent; +int g_hsvAccentH; -bool UpdateAccentColors() +bool UpdateAccentColor() { COLORREF dwAccentRGB; BOOL bIsColorOpaque; DwmGetColorizationColor(&dwAccentRGB, &bIsColorOpaque); - DWORD dwAccent = RGB2BGR(dwAccentRGB); + DWORD dwAccent = rgb2bgr(dwAccentRGB); if (g_dwAccent == dwAccent) { @@ -18,5 +19,10 @@ bool UpdateAccentColors() } g_dwAccent = dwAccent; + g_hsvAccentH = rgb2hsv({ + (double) GetRValue(dwAccent) / 255, + (double) GetGValue(dwAccent) / 255, + (double) GetBValue(dwAccent) / 255 }).h; + return true; } diff --git a/AccentColorizer/AccentColorHelper.h b/AccentColorizer/AccentColorHelper.h index e71d700..f2987c1 100644 --- a/AccentColorizer/AccentColorHelper.h +++ b/AccentColorizer/AccentColorHelper.h @@ -2,5 +2,6 @@ #include "framework.h" extern COLORREF g_dwAccent; +extern int g_hsvAccentH; -bool UpdateAccentColors(); +bool UpdateAccentColor(); diff --git a/AccentColorizer/BitmapHelper.cpp b/AccentColorizer/BitmapHelper.cpp index 57aff37..9201f8f 100644 --- a/AccentColorizer/BitmapHelper.cpp +++ b/AccentColorizer/BitmapHelper.cpp @@ -1,30 +1,7 @@ #include "BitmapHelper.h" -#pragma region Pixel Color -inline int PixClr(int val) +bool IterateBitmap(HBITMAP hbm, BitmapPixelHandler handler) { - return val & 0xFFFFFF; -} - -inline int PixR(BYTE* pPixel) -{ - return PixClr(pPixel[2]); -} -inline int PixG(BYTE* pPixel) -{ - return PixClr(pPixel[1]); -} -inline int PixB(BYTE* pPixel) -{ - return PixClr(pPixel[0]); -} -inline int PixA(BYTE* pPixel) -{ - return PixClr(pPixel[3]); -} -#pragma endregion - -bool RecolorizeBitmap(HBITMAP hbm, BitmapHandler handler) { BITMAP bm; GetObject(hbm, sizeof(bm), &bm); @@ -36,16 +13,20 @@ bool RecolorizeBitmap(HBITMAP hbm, BitmapHandler handler) { BYTE* pBits = new BYTE[bm.bmWidth * bm.bmHeight * 4]; GetBitmapBits(hbm, bm.bmWidth * bm.bmHeight * 4, pBits); - for (int y = 0; y < bm.bmHeight; y++) + BYTE* pPixel; + int x, y; + int r, g, b, a; + + for (y = 0; y < bm.bmHeight; y++) { - BYTE* pPixel = pBits + bm.bmWidth * 4 * y; + pPixel = pBits + bm.bmWidth * 4 * y; - for (int x = 0; x < bm.bmWidth; x++) + for (x = 0; x < bm.bmWidth; x++) { - int r = PixR(pPixel); // [2] - int g = PixG(pPixel); // [1] - int b = PixB(pPixel); // [0] - int a = PixA(pPixel); // [3] + r = pPixel[2] & 0xFFFFFF; + g = pPixel[1] & 0xFFFFFF; + b = pPixel[0] & 0xFFFFFF; + a = pPixel[3] & 0xFFFFFF; handler(r, g, b, a); diff --git a/AccentColorizer/BitmapHelper.h b/AccentColorizer/BitmapHelper.h index 37605b8..8c28111 100644 --- a/AccentColorizer/BitmapHelper.h +++ b/AccentColorizer/BitmapHelper.h @@ -1,5 +1,6 @@ #pragma once #include "framework.h" -typedef void (*BitmapHandler)(int& r, int& g, int& b, int& a); -bool RecolorizeBitmap(HBITMAP hbm, BitmapHandler handler); \ No newline at end of file +typedef void (*BitmapPixelHandler)(int& r, int& g, int& b, int& a); + +bool IterateBitmap(HBITMAP hbm, BitmapPixelHandler handler); \ No newline at end of file diff --git a/AccentColorizer/ColorHelper.cpp b/AccentColorizer/ColorHelper.cpp index d9b7083..0df80e5 100644 --- a/AccentColorizer/ColorHelper.cpp +++ b/AccentColorizer/ColorHelper.cpp @@ -1,10 +1,16 @@ #include "ColorHelper.h" +DWORD rgb2bgr(COLORREF color) +{ + return (color & 0xFF000000) | ((color & 0xFF0000) >> 16) | (color & 0x00FF00) | ((color & 0x0000FF) << 16); +} + + // https://stackoverflow.com/a/6930407 -hsv rgb2hsv(rgb in) +hsv_t rgb2hsv(rgb_t in) { - hsv out; + hsv_t out; double min, max, delta; min = in.r < in.g ? in.r : in.g; @@ -47,11 +53,11 @@ hsv rgb2hsv(rgb in) return out; } -rgb hsv2rgb(hsv in) +rgb_t hsv2rgb(hsv_t in) { double hh, p, q, t, ff; long i; - rgb out; + rgb_t out; if (in.s <= 0.0) { // < is bogus, just shuts up warnings out.r = in.v; @@ -103,15 +109,4 @@ rgb hsv2rgb(hsv in) break; } return out; -} - -int GetHSVh(COLORREF dwColor) -{ - return rgb2hsv( - { - (double)GetRValue(dwColor), - (double)GetGValue(dwColor), - (double)GetBValue(dwColor) - } - ).h; } \ No newline at end of file diff --git a/AccentColorizer/ColorHelper.h b/AccentColorizer/ColorHelper.h index 6f7e73b..2043b94 100644 --- a/AccentColorizer/ColorHelper.h +++ b/AccentColorizer/ColorHelper.h @@ -1,21 +1,17 @@ #pragma once #include "framework.h" -typedef struct { - double r; // a fraction between 0 and 1 - double g; // a fraction between 0 and 1 - double b; // a fraction between 0 and 1 -} rgb; +DWORD rgb2bgr(COLORREF rgb); -typedef struct { - double h; // angle in degrees - double s; // a fraction between 0 and 1 - double v; // a fraction between 0 and 1 -} hsv; +struct rgb_t +{ + double r, g, b; +}; -hsv rgb2hsv(rgb in); -rgb hsv2rgb(hsv in); +struct hsv_t +{ + double h, s, v; +}; -int GetHSVh(COLORREF dwColor); - -#define RGB2BGR(color) (color & 0xFF000000) | ((color & 0xFF0000) >> 16) | (color & 0x00FF00) | ((color & 0x0000FF) << 16) \ No newline at end of file +hsv_t rgb2hsv(rgb_t in); +rgb_t hsv2rgb(hsv_t in); \ No newline at end of file diff --git a/AccentColorizer/SettingsHelper.cpp b/AccentColorizer/SettingsHelper.cpp index 91fc641..1c68216 100644 --- a/AccentColorizer/SettingsHelper.cpp +++ b/AccentColorizer/SettingsHelper.cpp @@ -1,5 +1,6 @@ #include "SettingsHelper.h" #include "SystemHelper.h" + #include bool IsRegistryValueEnabled(LPCWSTR key, LPCWSTR value) diff --git a/AccentColorizer/StyleModifier.cpp b/AccentColorizer/StyleModifier.cpp index 737251a..4b5acd0 100644 --- a/AccentColorizer/StyleModifier.cpp +++ b/AccentColorizer/StyleModifier.cpp @@ -4,14 +4,15 @@ #include "AccentColorHelper.h" #include "SystemHelper.h" -int g_hsvAccentH; - bool g_bColorizeMenus; bool g_bColorizeProgressBar; -void StandardBitmapHandler(int& r, int& g, int& b, int& a) { - rgb rgbVal = { r, g, b }; - hsv hsvVal = rgb2hsv(rgbVal); +HTHEME hTheme = nullptr; + +void StandardBitmapPixelHandler(int& r, int& g, int& b, int& a) +{ + rgb_t rgbVal = { r, g, b }; + hsv_t hsvVal = rgb2hsv(rgbVal); hsvVal.h = g_hsvAccentH; @@ -22,297 +23,614 @@ void StandardBitmapHandler(int& r, int& g, int& b, int& a) { b = rgbVal.b; } -bool ModifyStyle(LPCWSTR pszClassList, int iPartId, int iStateId, int iPropId) +void SetCurrentTheme(LPCWSTR pszClassList) { - HBITMAP hBitmap; + if (hTheme) + { + CloseThemeData(hTheme); + } - HTHEME hTheme = OpenThemeData(GetForegroundWindow(), pszClassList); - GetThemeBitmap(hTheme, iPartId, iStateId, iPropId, GBF_DIRECT, &hBitmap); - CloseThemeData(hTheme); + hTheme = OpenThemeData(NULL, pszClassList); +} - return RecolorizeBitmap(hBitmap, StandardBitmapHandler); +bool ModifyStyle(int iPartId, int iStateId, int iPropId) +{ + HBITMAP hBitmap; + GetThemeBitmap(hTheme, iPartId, iStateId, iPropId, GBF_DIRECT, &hBitmap); + return IterateBitmap(hBitmap, StandardBitmapPixelHandler); } -void ModifyStyles() { +/// +/// At first glance, such refactoring looks useless, +/// premature and counterproductive, but +/// it speeded up the colorization four times, +/// i.e. tenths of a second +/// +void ModifyStyles() +{ int i, j, k; + // + - ModifyStyle(VSCLASS_BUTTON, BP_PUSHBUTTON, 0, TMT_DIBDATA); - for (j = 1; j <= 7; j++) { - ModifyStyle(VSCLASS_BUTTON, BP_CHECKBOX, 0, j); - ModifyStyle(VSCLASS_BUTTON, BP_RADIOBUTTON, 0, j); + SetCurrentTheme(VSCLASS_BUTTON); + // + ModifyStyle(BP_PUSHBUTTON, 0, TMT_DIBDATA); + for (j = 1; j <= 7; j++) + { + ModifyStyle(BP_CHECKBOX, 0, j); + ModifyStyle(BP_RADIOBUTTON, 0, j); } - for (j = 1; j <= 3; j++) { - ModifyStyle(VSCLASS_BUTTON, BP_GROUPBOX, 0, j); + for (j = 1; j <= 3; j++) + { + ModifyStyle(BP_GROUPBOX, 0, j); } + + SetCurrentTheme(VSCLASS_COMBOBOX); + // for (i = CP_DROPDOWNBUTTON; i <= CP_DROPDOWNBUTTONLEFT; i++) { - ModifyStyle(VSCLASS_COMBOBOX, i, 0, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); } + + + SetCurrentTheme(VSCLASS_EDIT); + // for (i = EP_EDITBORDER_NOSCROLL; i <= EP_EDITBORDER_HVSCROLL; i++) { - ModifyStyle(VSCLASS_EDIT, i, 0, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); } + + + SetCurrentTheme(VSCLASS_TAB); + // for (i = TABP_TABITEM; i <= TABP_TOPTABITEMBOTHEDGE; i++) { - ModifyStyle(VSCLASS_TAB, i, 0, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); } + + + SetCurrentTheme(VSCLASS_TRACKBAR); + // for (i = TKP_THUMB; i <= TKP_THUMBRIGHT; i++) { for (j = 1; j <= 7; j++) { - ModifyStyle(VSCLASS_TRACKBAR, i, 0, j); - ModifyStyle(VSCLASS_TRACKBAR, i, 0, j); + ModifyStyle(i, 0, j); + ModifyStyle(i, 0, j); } } + + + SetCurrentTheme(VSCLASS_LISTBOX); + // for (i = LBCP_BORDER_HSCROLL; i <= LBCP_ITEM; i++) { - ModifyStyle(VSCLASS_LISTBOX, i, 0, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); } + + + SetCurrentTheme(VSCLASS_SPIN); + // for (i = SPNP_UP; i <= SPNP_DOWNHORZ; i++) { - ModifyStyle(VSCLASS_SPIN, i, 0, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); + } + + + SetCurrentTheme(VSCLASS_HEADERSTYLE); + // + ModifyStyle(HP_HEADERITEM, 0, TMT_DIBDATA); + + + ///////////////////////////////////////////////////// + SetCurrentTheme(L"Toolbar"); + // + for (i = TP_BUTTON; i <= TP_SPLITBUTTONDROPDOWN; i++) + { + ModifyStyle(i, 1, TMT_DIBDATA); + } + + + SetCurrentTheme(L"ExplorerMenu::Toolbar"); + // + for (i = TP_BUTTON; i <= TP_SPLITBUTTONDROPDOWN; i++) + { + ModifyStyle(i, 1, TMT_DIBDATA); + } + + + SetCurrentTheme(L"Alternate::Toolbar"); + // + for (i = TP_BUTTON; i <= TP_SPLITBUTTONDROPDOWN; i++) + { + ModifyStyle(i, 1, TMT_DIBDATA); + } + + + SetCurrentTheme(L"Communications::Toolbar"); + // + for (i = TP_BUTTON; i <= TP_SPLITBUTTONDROPDOWN; i++) + { + ModifyStyle(i, 1, TMT_DIBDATA); } - ModifyStyle(VSCLASS_HEADERSTYLE, HP_HEADERITEM, 0, TMT_DIBDATA); + + + SetCurrentTheme(L"InfoPaneToolbar::Toolbar"); + // for (i = TP_BUTTON; i <= TP_SPLITBUTTONDROPDOWN; i++) { - ModifyStyle(L"Toolbar", i, 1, TMT_DIBDATA); - ModifyStyle(L"ExplorerMenu::Toolbar", i, 1, TMT_DIBDATA); - ModifyStyle(L"Alternate::Toolbar", i, 1, TMT_DIBDATA); - ModifyStyle(L"Communications::Toolbar", i, 1, TMT_DIBDATA); - ModifyStyle(L"InfoPaneToolbar::Toolbar", i, 1, TMT_DIBDATA); + ModifyStyle(i, 1, TMT_DIBDATA); } - ModifyStyle(L"BreadcrumbBar", 1, 0, TMT_DIBDATA); + ///////////////////////////////////////////////////// + + + SetCurrentTheme(L"BreadcrumbBar"); + // + ModifyStyle(1, 0, TMT_DIBDATA); + + + SetCurrentTheme(L"Explorer::TreeView"); + // for (i = 1; i <= 6; i++) { for (j = 1; j <= 2; j++) { - ModifyStyle(L"Explorer::TreeView", i, j, TMT_DIBDATA); + ModifyStyle(i, j, TMT_DIBDATA); } } + + + SetCurrentTheme(L"Explorer::ListView"); + // for (i = 1; i <= 10; i++) { for (j = 1; j <= 16; j++) { - ModifyStyle(L"Explorer::ListView", i, j, TMT_DIBDATA); + ModifyStyle(i, j, TMT_DIBDATA); } } - ModifyStyle(L"PreviewPane", 1, 1, TMT_DIBDATA); // Windows Vista/7 Explorer Bottom Details Panel + + SetCurrentTheme(L"PreviewPane"); + // + ModifyStyle(1, 1, TMT_DIBDATA); // Windows Vista/7 Explorer Bottom Details Panel + + + SetCurrentTheme(L"CommandModule"); + // for (i = 1; i <= 11; i++) { if (i == 8) continue; - ModifyStyle(L"CommandModule", i, 0, TMT_DIBDATA); - ModifyStyle(L"CommandModule", i, 1, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); + ModifyStyle(i, 1, TMT_DIBDATA); } - ModifyStyle(L"ItemsView::Header", 1, 0, TMT_DIBDATA); // Explorer File Groups Header + + + SetCurrentTheme(L"ItemsView"); + // for (i = 1; i <= 7; i++) { - ModifyStyle(L"ItemsView", 3, i, TMT_DIBDATA); + ModifyStyle(3, i, TMT_DIBDATA); } + + + SetCurrentTheme(L"ItemsView::Header"); + // + ModifyStyle(1, 0, TMT_DIBDATA); // Explorer File Groups Header for (i = 1; i <= 16; i++) { for (j = 1; j <= 16; j++) { - ModifyStyle(L"ItemsView::Header", i, j, TMT_DIBDATA); - ModifyStyle(L"ItemsView::ListView", i, j, TMT_DIBDATA); // Explorer File Selection + ModifyStyle(i, j, TMT_DIBDATA); } } + + ///////////////////////////////////////////////////// + SetCurrentTheme(L"ItemsView::ListView"); + // + for (i = 1; i <= 16; i++) + { + for (j = 1; j <= 16; j++) + { + ModifyStyle(i, j, TMT_DIBDATA); // Explorer File Selection + } + } for (i = 8; i <= 9; i++) { for (j = 1; j <= 7; j++) { for (k = 1; k <= 7; k++) { - ModifyStyle(L"ItemsView::ListView", i, j, k); - ModifyStyle(L"Explorer::ListView", i, j, k); - ModifyStyle(L"ListView", i, j, k); + ModifyStyle(i, j, k); } } } + + + SetCurrentTheme(L"ListView"); + // + for (i = 8; i <= 9; i++) + { + for (j = 1; j <= 7; j++) + { + for (k = 1; k <= 7; k++) + { + ModifyStyle(i, j, k); + } + } + } + + + SetCurrentTheme(L"Explorer::ListView"); + // + for (i = 8; i <= 9; i++) + { + for (j = 1; j <= 7; j++) + { + for (k = 1; k <= 7; k++) + { + ModifyStyle(i, j, k); + } + } + } + + + SetCurrentTheme(L"Explorer::TreeView"); + // for (j = 1; j <= 7; j++) { for (k = 1; k <= 7; k++) { - ModifyStyle(L"Explorer::TreeView", 4, j, k); + ModifyStyle(4, j, k); } } + ///////////////////////////////////////////////////// + + SetCurrentTheme(L"BB::Toolbar"); + // for (i = 1; i <= 4; i++) { - ModifyStyle(L"BB::Toolbar", i, 0, TMT_DIBDATA); // Explorer Breadcrumbs Highlight color + ModifyStyle(i, 0, TMT_DIBDATA); // Explorer Breadcrumbs Highlight color } - ModifyStyle(L"Go::Toolbar", 1, 1, TMT_DIBDATA); - ModifyStyle(L"InactiveGo::Toolbar", 1, 1, TMT_DIBDATA); + ///////////////////////////////////////////////////// + SetCurrentTheme(L"Go::Toolbar"); + // + ModifyStyle(1, 1, TMT_DIBDATA); + + + SetCurrentTheme(L"InactiveGo::Toolbar"); + // + ModifyStyle(1, 1, TMT_DIBDATA); + ///////////////////////////////////////////////////// + + + SetCurrentTheme(L"MaxGo::Toolbar"); + // + ModifyStyle(1, 1, TMT_DIBDATA); + + + ///////////////////////////////////////////////////// + SetCurrentTheme(L"LVPopup::Toolbar"); + // + ModifyStyle(1, 1, TMT_DIBDATA); + + + SetCurrentTheme(L"LVPopupBottom::Toolbar"); + // + ModifyStyle(1, 1, TMT_DIBDATA); + ///////////////////////////////////////////////////// + + - ModifyStyle(L"MaxGo::Toolbar", 1, 1, TMT_DIBDATA); + ///////////////////////////////////////////////////// + SetCurrentTheme(L"InactiveBB::Toolbar"); + // + ModifyStyle(3, 1, TMT_DIBDATA); + for (j = 1; j <= 6; j++) + { + ModifyStyle(4, j, j); + ModifyStyle(4, j, TMT_DIBDATA); + } - ModifyStyle(L"LVPopup::Toolbar", 1, 1, TMT_DIBDATA); - ModifyStyle(L"LVPopupBottom::Toolbar", 1, 1, TMT_DIBDATA); - ModifyStyle(L"InactiveBB::Toolbar", 3, 1, TMT_DIBDATA); + SetCurrentTheme(L"InactiveBBComposited::Toolbar"); + // for (j = 1; j <= 6; j++) { - ModifyStyle(L"InactiveBB::Toolbar", 4, j, j); - ModifyStyle(L"InactiveBB::Toolbar", 4, j, TMT_DIBDATA); - ModifyStyle(L"InactiveBBComposited::Toolbar", 4, j, j); - ModifyStyle(L"InactiveBBComposited::Toolbar", 4, j, TMT_DIBDATA); + ModifyStyle(4, j, j); + ModifyStyle(4, j, TMT_DIBDATA); } + ///////////////////////////////////////////////////// + + + SetCurrentTheme(L"DragDrop"); + // + ModifyStyle(7, 0, TMT_DIBDATA); + ModifyStyle(8, 0, TMT_DIBDATA); + - ModifyStyle(L"DragDrop", 7, 0, TMT_DIBDATA); - ModifyStyle(L"DragDrop", 8, 0, TMT_DIBDATA); + SetCurrentTheme(L"Header"); + // + ModifyStyle(1, 0, TMT_DIBDATA); - ModifyStyle(L"Header", 1, 0, TMT_DIBDATA); + SetCurrentTheme(L"PAUSE"); + // for (j = 1; j <= 7; j++) { - ModifyStyle(L"PAUSE", 1, 0, j); + ModifyStyle(1, 0, j); } + + SetCurrentTheme(L"Tab"); + // for (i = 1; i <= 8; i++) { - ModifyStyle(L"Tab", i, 1, TMT_DIBDATA); + ModifyStyle(i, 1, TMT_DIBDATA); } - // Explorer / Legacy Shell Date Picker + SetCurrentTheme(VSCLASS_MONTHCAL); // Explorer / Legacy Shell Date Picker + // for (i = 1; i <= 4; i++) { - ModifyStyle(VSCLASS_MONTHCAL, i, 0, TMT_DIBDATA); - ModifyStyle(VSCLASS_MONTHCAL, i, 1, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); + ModifyStyle(i, 1, TMT_DIBDATA); } for (j = 1; j <= 6; j++) { - ModifyStyle(VSCLASS_MONTHCAL, MC_GRIDCELLBACKGROUND, j, TMT_DIBDATA); + ModifyStyle(MC_GRIDCELLBACKGROUND, j, TMT_DIBDATA); } + + + SetCurrentTheme(L"DatePicker"); + // for (i = 1; i <= 2; i++) { for (j = 0; j <= 1; j++) { - ModifyStyle(L"DatePicker", i, j, 1); - ModifyStyle(L"DatePicker", i, j, TMT_DIBDATA); + ModifyStyle(i, j, 1); + ModifyStyle(i, j, TMT_DIBDATA); } } - ModifyStyle(L"Rebar", 6, 0, 2); + + SetCurrentTheme(L"Rebar"); + // + ModifyStyle(6, 0, 2); for (i = 4; i <= 6; i++) { - ModifyStyle(L"Rebar", i, 1, TMT_DIBDATA); - ModifyStyle(L"Rebar", i, 1, TMT_DIBDATA); + ModifyStyle(i, 1, TMT_DIBDATA); + ModifyStyle(i, 1, TMT_DIBDATA); } + + SetCurrentTheme(L"Desktop::ListView"); + // for (j = 0; j <= 9; j++) { - ModifyStyle(L"Desktop::ListView", 1, j, TMT_DIBDATA); // Desktop icons + ModifyStyle(1, j, TMT_DIBDATA); // Desktop icons } + ///////////////////////////////////////////////////// + SetCurrentTheme(L"TreeView"); + // for (i = 0; i <= 10; i++) { for (j = 0; j <= 10; j++) { for (k = 0; k <= 10; k++) { - ModifyStyle(L"TreeView", i, j, k); - ModifyStyle(L"Navigation", i, j, k); + ModifyStyle(i, j, k); } } } + SetCurrentTheme(L"Navigation"); + // + for (i = 0; i <= 10; i++) + { + for (j = 0; j <= 10; j++) + { + for (k = 0; k <= 10; k++) + { + ModifyStyle(i, j, k); + } + } + } + ///////////////////////////////////////////////////// + + + ///////////////////////////////////////////////////// + SetCurrentTheme(L"CopyClose"); + // for (j = 1; j <= 7; j++) { for (k = 1; k <= 7; k++) { - ModifyStyle(L"CopyClose", 1, j, k); - ModifyStyle(L"SearchBox", 2, j, k); - ModifyStyle(L"SearchBoxComposited::SearchBox", 2, j, k); - ModifyStyle(L"SearchButton::Toolbar", 3, j, k); - ModifyStyle(L"SearchButton::Toolbar", 4, j, k); + ModifyStyle(1, j, k); } } - // Taskbar Thumbnail Media Controls + + SetCurrentTheme(L"SearchBox"); + // + for (j = 1; j <= 7; j++) + { + for (k = 1; k <= 7; k++) + { + ModifyStyle(2, j, k); + } + } + + + SetCurrentTheme(L"SearchBoxComposited::SearchBox"); + // + for (j = 1; j <= 7; j++) + { + for (k = 1; k <= 7; k++) + { + ModifyStyle(2, j, k); + } + } + + + SetCurrentTheme(L"SearchButton::Toolbar"); + // + for (j = 1; j <= 7; j++) + { + for (k = 1; k <= 7; k++) + { + ModifyStyle(3, j, k); + ModifyStyle(4, j, k); + } + } + ///////////////////////////////////////////////////// + + + SetCurrentTheme(L"TaskbandExtendedUI"); // Taskbar Thumbnail Media Controls + // for (i = (g_winver >= WIN_10 ? 6 : 8); i <= (g_winver >= WIN_10 ? 9 : 11); i++) { - ModifyStyle(L"TaskbandExtendedUI", i, 0, TMT_DIBDATA); - ModifyStyle(L"TaskbandExtendedUI", i, 1, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); + ModifyStyle(i, 1, TMT_DIBDATA); } if (g_bColorizeMenus) { - ModifyStyle(L"Menu", 14, 0, TMT_DIBDATA); - ModifyStyle(L"Menu", 13, 0, TMT_DIBDATA); - ModifyStyle(L"Menu", 12, 0, TMT_DIBDATA); - ModifyStyle(L"Menu", 8, 0, TMT_DIBDATA); - ModifyStyle(L"Menu", 7, 0, TMT_DIBDATA); + SetCurrentTheme(L"Menu"); + // + ModifyStyle(14, 0, TMT_DIBDATA); + ModifyStyle(13, 0, TMT_DIBDATA); + ModifyStyle(12, 0, TMT_DIBDATA); + ModifyStyle(8, 0, TMT_DIBDATA); + ModifyStyle(7, 0, TMT_DIBDATA); // Menu Checkbox for (j = 0; j <= 7; j++) { for (k = 0; k <= 7; k++) { - ModifyStyle(L"Menu", 11, j, k); + ModifyStyle(11, j, k); } } } if (g_bColorizeProgressBar) { + SetCurrentTheme(L"Progress"); + // + ModifyStyle(5, 4, TMT_DIBDATA); for (i = 3; i <= 10; i++) { - ModifyStyle(L"Progress", i, 1, TMT_DIBDATA); - ModifyStyle(L"Indeterminate::Progress", i, 1, TMT_DIBDATA); + ModifyStyle(i, 1, TMT_DIBDATA); } - ModifyStyle(L"Progress", 5, 4, TMT_DIBDATA); - ModifyStyle(L"AB::AddressBand", 1, 1, TMT_DIBDATA); + + + SetCurrentTheme(L"Indeterminate::Progress"); + // + for (i = 3; i <= 10; i++) + { + ModifyStyle(i, 1, TMT_DIBDATA); + } + + + SetCurrentTheme(L"AB::AddressBand"); + // + ModifyStyle(1, 1, TMT_DIBDATA); } /** Tweaks for legacy components **/ - ModifyStyle(L"Communications::Rebar", 6, 0, TMT_DIBDATA); + SetCurrentTheme(L"Communications::Rebar"); + // + ModifyStyle(6, 0, TMT_DIBDATA); + + + SetCurrentTheme(L"StartPanel"); + // + ModifyStyle(1, 1, TMT_DIBDATA); + + + SetCurrentTheme(L"StartMenu::Toolbar"); + // + ModifyStyle(10, 1, TMT_DIBDATA); + ModifyStyle(12, 1, TMT_DIBDATA); - ModifyStyle(L"StartPanel", 1, 1, TMT_DIBDATA); - ModifyStyle(L"StartMenu::Toolbar", 10, 1, TMT_DIBDATA); - ModifyStyle(L"StartMenu::Toolbar", 12, 1, TMT_DIBDATA); + ///////////////////////////////////////////////////// + SetCurrentTheme(L"StartPanelPriv"); + // + for (i = 1; i <= 38; i++) + { + ModifyStyle(i, 0, TMT_DIBDATA); + } + + SetCurrentTheme(L"StartPanelComposited::StartPanelPriv"); + // for (i = 1; i <= 38; i++) { - ModifyStyle(L"StartPanelPriv", i, 0, TMT_DIBDATA); - ModifyStyle(L"StartPanelComposited::StartPanelPriv", i, 0, TMT_DIBDATA); + ModifyStyle(i, 0, TMT_DIBDATA); } + ///////////////////////////////////////////////////// if (g_winver < WIN_8) { + SetCurrentTheme(L"TaskDialog"); + // for (i = 1; i <= 8; i++) { - ModifyStyle(L"TaskDialog", 13, i, TMT_DIBDATA); + ModifyStyle(13, i, TMT_DIBDATA); } + + + ///////////////////////////////////////////////////// + SetCurrentTheme(L"Header"); + // for (i = 1; i <= 7; i++) { for (j = 1; j <= 12; j++) { for (k = 1; k <= 7; k++) { - ModifyStyle(L"Header", i, j, k); - ModifyStyle(L"ItemsView::Header", i, j, k); + ModifyStyle(i, j, k); } } } + + + SetCurrentTheme(L"ItemsView::Header"); + // + for (i = 1; i <= 7; i++) + { + for (j = 1; j <= 12; j++) + { + for (k = 1; k <= 7; k++) + { + ModifyStyle(i, j, k); + } + } + } + ///////////////////////////////////////////////////// + + + SetCurrentTheme(L"ScrollBar"); + // for (i = 1; i <= 10; i++) { for (k = 1; k <= 4; k++) { - ModifyStyle(L"ScrollBar", i, 0, k); + ModifyStyle(i, 0, k); } } } -} -void ModifyStyles(COLORREF accentColor) -{ - g_hsvAccentH = GetHSVh(accentColor); - - ModifyStyles(); + // + CloseThemeData(hTheme); + hTheme = nullptr; } \ No newline at end of file diff --git a/AccentColorizer/StyleModifier.h b/AccentColorizer/StyleModifier.h index 082f6ea..d00d82e 100644 --- a/AccentColorizer/StyleModifier.h +++ b/AccentColorizer/StyleModifier.h @@ -4,4 +4,4 @@ extern bool g_bColorizeMenus; extern bool g_bColorizeProgressBar; -void ModifyStyles(COLORREF accentColor); \ No newline at end of file +void ModifyStyles(); \ No newline at end of file diff --git a/AccentColorizer/SysColorsModifier.cpp b/AccentColorizer/SysColorsModifier.cpp index 7ecd19c..580b99a 100644 --- a/AccentColorizer/SysColorsModifier.cpp +++ b/AccentColorizer/SysColorsModifier.cpp @@ -2,32 +2,35 @@ #include "ColorHelper.h" #include "AccentColorHelper.h" -const int aSysElements[] = { +constexpr int aSysElements[] = { COLOR_ACTIVECAPTION, COLOR_GRADIENTACTIVECAPTION, COLOR_HIGHLIGHT, COLOR_HOTLIGHT, COLOR_MENUHILIGHT }; -const size_t nSysElements = sizeof(aSysElements) / sizeof(*aSysElements); - -void ModifySysColors(COLORREF dwAccentColor) { - int hsvAccentH = GetHSVh(dwAccentColor); +constexpr size_t nSysElements = sizeof(aSysElements) / sizeof(*aSysElements); +void ModifySysColors() +{ DWORD aNewColors[nSysElements]; + COLORREF dwCurrentColor; + rgb_t rgbVal; + hsv_t hsvVal; + for (int i = 0; i < nSysElements; i++) { - COLORREF dwCurrentColor = GetSysColor(aSysElements[i]); + dwCurrentColor = GetSysColor(aSysElements[i]); - rgb rgbVal = rgb{ + rgbVal = { (double)GetRValue(dwCurrentColor), (double)GetGValue(dwCurrentColor), (double)GetBValue(dwCurrentColor) }; - hsv hsvVal = rgb2hsv(rgbVal); + hsvVal = rgb2hsv(rgbVal); - hsvVal.h = hsvAccentH; + hsvVal.h = g_hsvAccentH; rgbVal = hsv2rgb(hsvVal); diff --git a/AccentColorizer/SysColorsModifier.h b/AccentColorizer/SysColorsModifier.h index 07bda6d..422e50e 100644 --- a/AccentColorizer/SysColorsModifier.h +++ b/AccentColorizer/SysColorsModifier.h @@ -1,4 +1,4 @@ #pragma once #include "framework.h" -void ModifySysColors(COLORREF accentColor); \ No newline at end of file +void ModifySysColors(); \ No newline at end of file diff --git a/AccentColorizer/main.cpp b/AccentColorizer/main.cpp index f113b18..978b60a 100644 --- a/AccentColorizer/main.cpp +++ b/AccentColorizer/main.cpp @@ -4,12 +4,12 @@ #include "SettingsHelper.h" #include "SystemHelper.h" -const LPCWSTR szWindowClass = L"ACCENTCOLORIZER"; +constexpr LPCWSTR szWindowClass = L"ACCENTCOLORIZER"; HANDLE hMutex; void ApplyAccentColorization() { - if (!UpdateAccentColors()) + if (!UpdateAccentColor()) { // Accent Colors have not been changed. // There's a bug in Windows 10 1809+ because of which @@ -18,8 +18,8 @@ void ApplyAccentColorization() // Apparently it is fixed in Windows 11 version 22H2 return; } - ModifySysColors(g_dwAccent); - ModifyStyles(g_dwAccent); + ModifySysColors(); + ModifyStyles(); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) @@ -73,7 +73,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, wcex.lpszClassName = szWindowClass; if (!RegisterClassEx(&wcex)) { - return 1; + return 2; } HWND hWnd = CreateWindowEx(0, szWindowClass, nullptr, 0, 0, 0, 0, 0, nullptr, NULL, NULL, NULL);