From 505b71b47294d2cee3c2accbf82e1147d9de8533 Mon Sep 17 00:00:00 2001 From: Dart Vanya Date: Fri, 22 Nov 2024 03:31:57 +0300 Subject: [PATCH] PhReInitializeTheme: runtime theme switching on ImmersiveColorSet message - Theme can be changed at runtime w/o restart by EnableThemeSupport and EnableThemeUseWindowsTheme. All PH/PV windows and dialogs will be redrawed automatically. - If EnableThemeUseWindowsTheme enabled theme will be switched automatically when Windows theme is changing. - Streamer mode, acrylic, theme custom colors settings are applied immediately on all windows w/o restart. - TreeNew: fix custom ForeColor for dark mode. --- SystemInformer/SystemInformer.def | 3 +- SystemInformer/actions.c | 4 +- SystemInformer/main.c | 25 +- SystemInformer/mainwnd.c | 39 +- SystemInformer/options.c | 47 +- SystemInformer/searchbox.c | 12 +- phlib/delayhook.c | 562 ++--- phlib/emenu.c | 35 +- phlib/guisup.c | 37 +- phlib/include/guisup.h | 76 +- phlib/include/guisupp.h | 4 + phlib/include/searchbox.h | 6 +- phlib/searchbox.c | 24 +- phlib/theme.c | 2764 +++++++++++++------------ phlib/treenew.c | 3 +- plugins/ExtendedTools/disktab.c | 12 +- plugins/ExtendedTools/fwtab.c | 10 +- plugins/ExtendedTools/objprp.c | 9 + plugins/HardwareDevices/deviceprops.c | 5 +- plugins/HardwareDevices/devicetree.c | 7 +- plugins/HardwareDevices/diskdetails.c | 7 +- plugins/ToolStatus/main.c | 4 + plugins/WindowExplorer/wndprp.c | 5 +- plugins/WindowExplorer/wndtree.c | 2 +- tools/peview/include/peview.h | 6 +- tools/peview/main.c | 2 +- tools/peview/options.c | 23 +- tools/peview/peprp.c | 6 + tools/peview/peprpwnd.c | 27 + tools/peview/searchbox.c | 12 +- tools/peview/settings.c | 23 +- 31 files changed, 2026 insertions(+), 1775 deletions(-) diff --git a/SystemInformer/SystemInformer.def b/SystemInformer/SystemInformer.def index 35a9f33dbd1c..9cc03293678f 100644 --- a/SystemInformer/SystemInformer.def +++ b/SystemInformer/SystemInformer.def @@ -888,7 +888,7 @@ EXPORTS PhRegisterWindowCallback @1831 NONAME PhUnregisterWindowCallback @1832 NONAME PhInitializeWindowTheme @1833 NONAME - PhReInitializeWindowTheme @1834 NONAME + PhReInitializeTheme @1834 NONAME PhImageListCreate @1835 NONAME PhImageListDestroy @1836 NONAME PhImageListSetIconSize @1837 NONAME @@ -904,6 +904,7 @@ EXPORTS PhThemeWindowDrawRebar @1847 NONAME PhThemeWindowDrawToolbar @1848 NONAME PhWindowThemeControlColor @1849 NONAME + PhReInitializeStreamerMode @2062 NONAME ; hndlinfo PhEnumObjectTypes @1850 NONAME diff --git a/SystemInformer/actions.c b/SystemInformer/actions.c index 113b33157ff3..97a7fef986d2 100644 --- a/SystemInformer/actions.c +++ b/SystemInformer/actions.c @@ -3840,8 +3840,6 @@ HRESULT CALLBACK PhpUiServiceInitializeDialogCallbackProc( PhSetWindowProcedure(WindowHandle, PhpUiServiceProgressDialogWndProc); PhShowServiceProgressDialogConfirmMessage(context); - - PhInitializeWindowTheme(WindowHandle, PhEnableThemeSupport); } break; } @@ -5855,7 +5853,7 @@ BOOLEAN PhUiFreeMemory( static BOOLEAN PhpShowErrorHandle( _In_ HWND WindowHandle, _In_ PCWSTR Verb, - _In_ PCWSTR Verb2, + _In_opt_ PCWSTR Verb2, _In_ PPH_HANDLE_ITEM Handle, _In_ NTSTATUS Status, _In_opt_ ULONG Win32Result diff --git a/SystemInformer/main.c b/SystemInformer/main.c index 9383b853bc97..9c511a19fe6a 100644 --- a/SystemInformer/main.c +++ b/SystemInformer/main.c @@ -1194,7 +1194,7 @@ VOID PhpInitializeSettings( for (ULONG i = 0; i < PhMaxPrecisionUnit; i++) PhMaxPrecisionLimit /= 10; PhEnableWindowText = !!PhGetIntegerSetting(L"EnableWindowText"); - PhEnableThemeSupport = PhIsThemeSupportEnabled(); + PhEnableStreamerMode = !!PhGetIntegerSetting(L"EnableStreamerMode"); PhThemeWindowForegroundColor = PhGetIntegerSetting(L"ThemeWindowForegroundColor"); PhThemeWindowBackgroundColor = PhGetIntegerSetting(L"ThemeWindowBackgroundColor"); PhThemeWindowBackground2Color = PhGetIntegerSetting(L"ThemeWindowBackground2Color"); @@ -1203,7 +1203,9 @@ VOID PhpInitializeSettings( PhThemeWindowTextColor = PhGetIntegerSetting(L"ThemeWindowTextColor"); PhEnableThemeAcrylicSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicSupport"); PhEnableThemeAcrylicWindowSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicWindowSupport"); + PhEnableThemeAnimation = !!PhGetIntegerSetting(L"EnableThemeAnimation"); PhEnableThemeNativeButtons = !!PhGetIntegerSetting(L"EnableThemeNativeButtons"); + PhEnableThemeTabBorders = !!PhGetIntegerSetting(L"EnableThemeTabBorders"); PhEnableThemeListviewBorder = !!PhGetIntegerSetting(L"TreeListBorderEnable"); PhEnableDeferredLayout = !!PhGetIntegerSetting(L"EnableDeferredLayout"); PhEnableServiceNonPoll = !!PhGetIntegerSetting(L"EnableServiceNonPoll"); @@ -1212,6 +1214,27 @@ VOID PhpInitializeSettings( PhEnableKsiSupport = !!PhGetIntegerSetting(L"KsiEnable") && !PhStartupParameters.NoKph && !PhIsExecutingInWow64(); PhEnableKsiWarnings = !!PhGetIntegerSetting(L"KsiEnableWarnings"); + if (!PhThemeWindowBackgroundBrush) + PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor); + + // If AppMode is set to PreferredAppModeDarkOnDark, PhShouldAppsUseDarkMode should return current Windows app color mode. + // It's weird that sometimes it can return incorrect inverted value (idk why). + // In this case use PhGetAppsUseLightTheme() to retrieve raw value from registry. + // + // When app mode set to always dark/light all subsequent calls to PhShouldAppsUseDarkMode always ignore + // the current Windows app color mode. Possible return values are: + // + // ---PreferredAppMode--- | ---PhShouldAppsUseDarkMode()--- + // -------------------------------|---------------------------------- + // PreferredAppModeDisabled | Windows app color mode ? + // PreferredAppModeDarkOnDark | Windows app color mode + // PreferredAppModeDarkAlways | always return TRUE + // PreferredAppModeLightAlways | always return FALSE + + PH_THEME_SET_PREFFEREDAPPMODE(L"EnableThemeSupport", L"EnableThemeUseWindowsTheme"); + + PhEnableThemeSupport = PH_THEME_GET_GENERAL_SWITCH(L"EnableThemeSupport"); + if (PhGetIntegerSetting(L"SampleCountAutomatic")) { ULONG sampleCount; diff --git a/SystemInformer/mainwnd.c b/SystemInformer/mainwnd.c index dfe75ca9fc3d..5d84398e0113 100644 --- a/SystemInformer/mainwnd.c +++ b/SystemInformer/mainwnd.c @@ -130,12 +130,12 @@ BOOLEAN PhMainWndInitialization( // Initialize window settings. PhMwpLoadSettings(PhMainWndHandle); - // Initialize window theme. - PhInitializeWindowTheme(PhMainWndHandle, PhEnableThemeSupport); - // Initialize window menu. PhMwpInitializeMainMenu(PhMainWndHandle); + // Initialize window theme. + PhInitializeWindowTheme(PhMainWndHandle, PhEnableThemeSupport); + // Initialize providers. PhMwpInitializeProviders(); @@ -634,6 +634,29 @@ VOID PhMwpOnEndSession( PhExitApplication(STATUS_SUCCESS); } +static NTSTATUS PhMwpReInitializeThemeThread( + _In_ PVOID Context + ) +{ + BOOLEAN currentTheme; + + //currentTheme = PhShouldAppsUseDarkMode(); + currentTheme = PhGetAppsUseLightTheme(); + + dprintf("PhMwpPhReInitializeThemeThread: currentTheme = %d, PhEnableThemeSupport = %d\r\n", currentTheme, PhEnableThemeSupport); + + if (PhEnableThemeSupport != currentTheme) + { + PhEnableThemeSupport = currentTheme; + + PhReInitializeTheme(PhEnableThemeSupport); + + PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackSettingsUpdated), NULL); + }; + + return STATUS_SUCCESS; +} + VOID PhMwpOnSettingChange( _In_ HWND WindowHandle, _In_opt_ ULONG Action, @@ -661,10 +684,11 @@ VOID PhMwpOnSettingChange( // Reload dark theme metrics - //if (PhEqualStringZ(Metric, L"ImmersiveColorSet", TRUE)) - //{ - // NOTHING; - //} + // Implemented (Dart Vanya) + if (HANDLE_COLORSCHEMECHANGE_MESSAGE(Action, Metric, L"EnableThemeSupport", L"EnableThemeUseWindowsTheme")) + { + PhCreateThread2(PhMwpReInitializeThemeThread, NULL); + } } //if (Action == SPI_SETNONCLIENTMETRICS && Metric && PhEqualStringZ(Metric, L"WindowMetrics", TRUE)) @@ -2986,7 +3010,6 @@ VOID PhMwpInitializeMainMenu( return; PhEMenuToHMenu2(menuHandle, PhpCreateMainMenu(ULONG_MAX), 0, NULL); - PhInitializeWindowThemeMainMenu(menuHandle); PhSetHMenuNotify(menuHandle); SetMenu(WindowHandle, menuHandle); diff --git a/SystemInformer/options.c b/SystemInformer/options.c index 2fc8e3217c1f..aba5605ecf28 100644 --- a/SystemInformer/options.c +++ b/SystemInformer/options.c @@ -1519,7 +1519,46 @@ static VOID PhpOptionsNotifyChangeCallback( PhReloadSettingsProcessTreeList(); PhSiNotifyChangeSettings(); - //PhReInitializeWindowTheme(PhMainWndHandle); + PhThemeWindowForegroundColor = PhGetIntegerSetting(L"ThemeWindowForegroundColor"); + COLORREF oldPhThemeWindowBackgroundColor = PhThemeWindowBackgroundColor; + PhThemeWindowBackgroundColor = PhGetIntegerSetting(L"ThemeWindowBackgroundColor"); + PhThemeWindowBackground2Color = PhGetIntegerSetting(L"ThemeWindowBackground2Color"); + PhThemeWindowHighlightColor = PhGetIntegerSetting(L"ThemeWindowHighlightColor"); + PhThemeWindowHighlight2Color = PhGetIntegerSetting(L"ThemeWindowHighlight2Color"); + PhThemeWindowTextColor = PhGetIntegerSetting(L"ThemeWindowTextColor"); + PhEnableThemeNativeButtons = !!PhGetIntegerSetting(L"EnableThemeNativeButtons"); + PhEnableThemeTabBorders = !!PhGetIntegerSetting(L"EnableThemeTabBorders"); + PhEnableThemeAcrylicSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicSupport"); + BOOLEAN oldAcrylicWindowSupport = PhEnableThemeAcrylicWindowSupport; + PhEnableThemeAcrylicWindowSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicWindowSupport"); + BOOLEAN oldStreamerMode = PhEnableStreamerMode; + PhEnableStreamerMode = !!PhGetIntegerSetting(L"EnableStreamerMode"); + + PH_THEME_SET_PREFFEREDAPPMODE(L"EnableThemeSupport", L"EnableThemeUseWindowsTheme"); + + BOOLEAN oldTheme = PhEnableThemeSupport; + PhEnableThemeSupport = PH_THEME_GET_GENERAL_SWITCH(L"EnableThemeSupport"); + + if (oldPhThemeWindowBackgroundColor != PhThemeWindowBackgroundColor && PhThemeWindowBackgroundBrush) + { + DeleteBrush(PhThemeWindowBackgroundBrush); + PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor); + + if (PhEnableThemeSupport) // replace old destroyed menu brush with the new one + { + PhInitializeWindowThemeMenu(PhMainWndHandle, TRUE); + } + } + + if (PhEnableThemeSupport != oldTheme || PhEnableThemeAcrylicWindowSupport != oldAcrylicWindowSupport) + { + PhReInitializeTheme(PhEnableThemeSupport); + } + + if (PhEnableStreamerMode != oldStreamerMode) + { + PhReInitializeStreamerMode(PhEnableStreamerMode); + } PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackSettingsUpdated), NULL); @@ -1677,10 +1716,10 @@ static VOID PhpAdvancedPageSave( SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_COLUMN_HEADER_TOTALS, L"TreeListEnableHeaderTotals"); SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_GRAPH_SCALING, L"EnableGraphMaxScale"); SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_CYCLE_CPU_USAGE, L"EnableCycleCpuUsage"); - SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_SUPPORT, L"EnableThemeSupport"); - SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_WINDOWS_THEME, L"EnableThemeUseWindowsTheme"); + SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_SUPPORT, L"EnableThemeSupport"); + SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_WINDOWS_THEME, L"EnableThemeUseWindowsTheme"); SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_START_ASADMIN, L"EnableStartAsAdmin"); - SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_STREAM_MODE, L"EnableStreamerMode"); + SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_STREAM_MODE, L"EnableStreamerMode"); SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_SILENT_CRASH_NOTIFY, L"EnableSilentCrashNotify"); SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_MONOSPACE, L"EnableMonospaceFont"); //SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_LINUX_SUPPORT, L"EnableLinuxSubsystemSupport"); diff --git a/SystemInformer/searchbox.c b/SystemInformer/searchbox.c index 9bbb34648dfe..c59d227230e8 100644 --- a/SystemInformer/searchbox.c +++ b/SystemInformer/searchbox.c @@ -24,10 +24,14 @@ VOID PhCreateSearchControl( ParentWindowHandle, WindowHandle, BannerText, - PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_DARK), - PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_DARK), - PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_DARK), - PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_DARK), + MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_LIGHT), + MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_LIGHT), + MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_LIGHT), + MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_LIGHT), + MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_DARK), + MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_DARK), + MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_DARK), + MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_DARK), L"SearchControlRegex", L"SearchControlCaseSensitive", Callback, diff --git a/phlib/delayhook.c b/phlib/delayhook.c index 1d7f3dfa7508..abd817e5fd5b 100644 --- a/phlib/delayhook.c +++ b/phlib/delayhook.c @@ -73,7 +73,7 @@ LRESULT CALLBACK PhMenuWindowHookProcedure( if (PhEnableThemeAcrylicSupport) { // Note: DWM crashes if called from WM_NCCREATE (dmex) - PhSetWindowAcrylicCompositionColor(WindowHandle, MakeABGRFromCOLORREF(0, RGB(10, 10, 10))); + PhSetWindowAcrylicCompositionColor(WindowHandle, MakeABGRFromCOLORREF(0, RGB(10, 10, 10)), TRUE); } } } @@ -124,7 +124,7 @@ LRESULT CALLBACK PhDialogWindowHookProcedure( if (PhEnableThemeSupport && PhEnableThemeAcrylicWindowSupport) { // Note: DWM crashes if called from WM_NCCREATE (dmex) - PhSetWindowAcrylicCompositionColor(WindowHandle, MakeABGRFromCOLORREF(0, RGB(10, 10, 10))); + PhSetWindowAcrylicCompositionColor(WindowHandle, MakeABGRFromCOLORREF(0, RGB(10, 10, 10)), TRUE); } } } @@ -144,6 +144,7 @@ LRESULT CALLBACK PhRebarWindowHookProcedure( switch (WindowMessage) { case WM_CTLCOLOREDIT: + if (PhEnableThemeSupport) { HDC hdc = (HDC)wParam; @@ -170,17 +171,15 @@ LRESULT CALLBACK PhComboBoxWindowHookProcedure( switch (WindowMessage) { case WM_NCCREATE: + if (PhEnableStreamerMode) { //CREATESTRUCT* createStruct = (CREATESTRUCT*)lParam; COMBOBOXINFO info = { sizeof(COMBOBOXINFO) }; - if (SendMessage(WindowHandle, CB_GETCOMBOBOXINFO, 0, (LPARAM)&info)) + if (SendMessage(WindowHandle, CB_GETCOMBOBOXINFO, 0, (LPARAM)&info) && info.hwndList) { - if (PhEnableStreamerMode) - { - if (SetWindowDisplayAffinity_Import()) - SetWindowDisplayAffinity_Import()(info.hwndList, WDA_EXCLUDEFROMCAPTURE); - } + if (SetWindowDisplayAffinity_Import()) + SetWindowDisplayAffinity_Import()(info.hwndList, WDA_EXCLUDEFROMCAPTURE); } } break; @@ -198,15 +197,28 @@ LRESULT CALLBACK PhStaticWindowHookProcedure( { if (WindowMessage == WM_NCCREATE) { + CREATESTRUCT* createStruct = (CREATESTRUCT*)lParam; + WCHAR windowClassName[MAX_PATH]; LONG_PTR style = PhGetWindowStyle(WindowHandle); - if ((style & SS_ICON) == SS_ICON) + if (createStruct->hwndParent) { - PhSetWindowContext(WindowHandle, SCHAR_MAX, (PVOID)TRUE); + GETCLASSNAME_OR_NULL(createStruct->hwndParent, windowClassName); + + if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE)) + { + PhSetWindowContext(WindowHandle, SHRT_MAX, (PVOID)'TNSB'); + } + else if (PhEqualStringZ(windowClassName, L"CHECKLIST_ACLUI", FALSE)) + { + PhSetWindowContext(WindowHandle, SHRT_MAX, (PVOID)'ACLC'); + } } } - if (WindowMessage != WM_KILLFOCUS && !PhGetWindowContext(WindowHandle, SCHAR_MAX)) + LONG contextTag = HandleToLong(PhGetWindowContext(WindowHandle, SHRT_MAX)); + + if (!(contextTag)) return CallWindowProc(PhDefaultStaticWindowProcedure, WindowHandle, WindowMessage, wParam, lParam); switch (WindowMessage) @@ -215,21 +227,27 @@ LRESULT CALLBACK PhStaticWindowHookProcedure( PhRemoveWindowContext(WindowHandle, SCHAR_MAX); break; case WM_ERASEBKGND: - return TRUE; + if (contextTag == 'TNSB') + { + HDC hdc = (HDC)wParam; + RECT rect; + + GetClipBox(hdc, &rect); + SetDCBrushColor(hdc, PhEnableThemeSupport ? RGB(23, 23, 23) : GetSysColor(COLOR_BTNFACE)); + FillRect(hdc, &rect, PhGetStockBrush(DC_BRUSH)); + return TRUE; + } + break; case WM_KILLFOCUS: + if (contextTag == 'ACLC') { - WCHAR windowClassName[MAX_PATH]; + RECT rectClient; HWND ParentHandle = GetParent(WindowHandle); - if (!GetClassName(ParentHandle, windowClassName, RTL_NUMBER_OF(windowClassName))) - windowClassName[0] = UNICODE_NULL; - if (PhEqualStringZ(windowClassName, L"CHECKLIST_ACLUI", FALSE)) - { - RECT rectClient; - GetClientRect(WindowHandle, &rectClient); - PhInflateRect(&rectClient, 2, 2); - MapWindowRect(WindowHandle, ParentHandle, &rectClient); - InvalidateRect(ParentHandle, &rectClient, TRUE); // fix the annoying white border left by the previous active control - } + + GetClientRect(WindowHandle, &rectClient); + PhInflateRect(&rectClient, 2, 2); + MapWindowRect(WindowHandle, ParentHandle, &rectClient); + InvalidateRect(ParentHandle, &rectClient, TRUE); // fix the annoying white border left by the previous active control } break; case WM_PAINT: @@ -237,13 +255,14 @@ LRESULT CALLBACK PhStaticWindowHookProcedure( HICON iconHandle; PAINTSTRUCT ps; RECT clientRect; - WCHAR windowClassName[MAX_PATH]; - if (!GetClassName(GetParent(WindowHandle), windowClassName, RTL_NUMBER_OF(windowClassName))) - windowClassName[0] = UNICODE_NULL; - if (PhEqualStringZ(windowClassName, L"CHECKLIST_ACLUI", FALSE)) + switch (contextTag) { - if (iconHandle = (HICON)(UINT_PTR)CallWindowProc(PhDefaultStaticWindowProcedure, WindowHandle, STM_GETICON, 0, 0)) + case 'TNSB': + return DefWindowProc(WindowHandle, WindowMessage, wParam, lParam); + case 'ACLC': + if (PhEnableThemeSupport && + (iconHandle = (HICON)(UINT_PTR)CallWindowProc(PhDefaultStaticWindowProcedure, WindowHandle, STM_GETICON, 0, 0))) { static PH_INITONCE initOnce = PH_INITONCE_INIT; static HFONT hCheckFont = NULL; @@ -292,7 +311,8 @@ LRESULT CALLBACK PhStaticWindowHookProcedure( 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, - VARIABLE_PITCH, L"Segoe UI"); + VARIABLE_PITCH, L"Segoe UI" + ); PhEndInitOnce(&initOnce); } @@ -312,34 +332,6 @@ LRESULT CALLBACK PhStaticWindowHookProcedure( return 0; } } - //else if (iconHandle = (HICON)(UINT_PTR)CallWindowProc(PhDefaultStaticWindowProcedure, WindowHandle, STM_GETICON, 0, 0)) // Static_GetIcon(WindowHandle, 0) - //{ - // PAINTSTRUCT ps; - // if (PhGetWindowContext(GetParent(WindowHandle), LONG_MAX) && - // BeginPaint(WindowHandle, &ps)) - // { - // // Fix artefacts when window moving back from off-screen (Dart Vanya) - // hdc = GetDC(WindowHandle); - // GetClientRect(WindowHandle, &clientRect); - - // FillRect(hdc, &clientRect, PhThemeWindowBackgroundBrush); - - // DrawIconEx( - // hdc, - // clientRect.left, - // clientRect.top, - // iconHandle, - // clientRect.right - clientRect.left, - // clientRect.bottom - clientRect.top, - // 0, - // NULL, - // DI_NORMAL - // ); - - // ReleaseDC(WindowHandle, hdc); - // EndPaint(WindowHandle, &ps); - // } - //} } } @@ -572,7 +564,7 @@ LRESULT CALLBACK PhStatusBarWindowHookProcedure( context->CursorPos.y = LONG_MIN; PhSetWindowContext(WindowHandle, LONG_MAX, context); } - else + else if (PhEnableThemeSupport) { context = PhGetWindowContext(WindowHandle, LONG_MAX); } @@ -723,7 +715,7 @@ LRESULT CALLBACK PhEditWindowHookProcedure( HRGN updateRegion; // The searchbox control does its own theme drawing. - if (PhGetWindowContext(WindowHandle, SHRT_MAX)) + if (!PhEnableThemeSupport || PhGetWindowContext(WindowHandle, SHRT_MAX)) break; updateRegion = (HRGN)wParam; @@ -953,8 +945,7 @@ LRESULT CALLBACK PhHeaderWindowHookProcedure( { WCHAR windowClassName[MAX_PATH]; - if (!GetClassName(createStruct->hwndParent, windowClassName, RTL_NUMBER_OF(windowClassName))) - windowClassName[0] = UNICODE_NULL; + GETCLASSNAME_OR_NULL(createStruct->hwndParent, windowClassName); if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE)) { @@ -962,8 +953,6 @@ LRESULT CALLBACK PhHeaderWindowHookProcedure( if (BooleanFlagOn(windowStyle, TN_STYLE_CUSTOM_HEADERDRAW)) { - PhSetControlTheme(WindowHandle, L"DarkMode_ItemsView"); - return CallWindowProc(PhDefaultHeaderWindowProcedure, WindowHandle, WindowMessage, wParam, lParam); } } @@ -975,12 +964,8 @@ LRESULT CALLBACK PhHeaderWindowHookProcedure( context->CursorPos.y = LONG_MIN; context->ParentWindow = createStruct->hwndParent; PhSetWindowContext(WindowHandle, LONG_MAX, context); - - PhSetControlTheme(WindowHandle, L"DarkMode_ItemsView"); - - InvalidateRect(WindowHandle, NULL, FALSE); } - else + else if (PhEnableThemeSupport) { context = PhGetWindowContext(WindowHandle, LONG_MAX); } @@ -1070,7 +1055,6 @@ LRESULT CALLBACK PhHeaderWindowHookProcedure( if (context->ThemeHandle) PhCloseThemeData(context->ThemeHandle); PhFree(context); - PhSetControlTheme(WindowHandle, L"Explorer"); break; } @@ -1400,8 +1384,6 @@ typedef struct _TASKDIALOG_WINDOW_CONTEXT #define TASKDIALOG_CONTEXT_TAG (ULONG)'TDLG' -#define GETCLASSNAME_OR_NULL(WindowHandle, ClassName) if (!GetClassName(WindowHandle, ClassName, RTL_NUMBER_OF(ClassName))) ClassName[0] = UNICODE_NULL - HRESULT CALLBACK ThemeTaskDialogCallbackHook( _In_ HWND hwndDlg, _In_ UINT uMsg, @@ -1434,27 +1416,30 @@ HRESULT PhDrawThemeBackgroundHook( WCHAR className[MAX_PATH]; BOOLEAN hasThemeClass = PhGetThemeClass(Theme, className, RTL_NUMBER_OF(className)); - if (WindowsVersion >= WINDOWS_11 && hasThemeClass) + if (PhEnableThemeSupport) { - if (PhEqualStringZ(className, VSCLASS_MENU, TRUE)) + if (WindowsVersion >= WINDOWS_11 && hasThemeClass) { - if (PartId == MENU_POPUPGUTTER || PartId == MENU_POPUPBORDERS) + if (PhEqualStringZ(className, VSCLASS_MENU, TRUE)) { - FillRect(Hdc, Rect, PhThemeWindowBackgroundBrush); - return S_OK; + if (PartId == MENU_POPUPGUTTER || PartId == MENU_POPUPBORDERS) + { + FillRect(Hdc, Rect, PhThemeWindowBackgroundBrush); + return S_OK; + } } } - } - if (hasThemeClass && PhEqualStringZ(className, VSCLASS_PROGRESS, TRUE) - /*|| WindowsVersion < WINDOWS_11 && WindowFromDC(Hdc) == NULL*/) - { - if (PartId == PP_TRANSPARENTBAR || PartId == PP_TRANSPARENTBARVERT) // Progress bar background + if (hasThemeClass && PhEqualStringZ(className, VSCLASS_PROGRESS, TRUE) + /*|| WindowsVersion < WINDOWS_11 && WindowFromDC(Hdc) == NULL*/) { - FillRect(Hdc, Rect, PhThemeWindowBackgroundBrush); - SetDCBrushColor(Hdc, RGB(0x60, 0x60, 0x60)); - FrameRect(Hdc, Rect, PhGetStockBrush(DC_BRUSH)); - return S_OK; + if (PartId == PP_TRANSPARENTBAR || PartId == PP_TRANSPARENTBARVERT) // Progress bar background + { + FillRect(Hdc, Rect, PhThemeWindowBackgroundBrush); + SetDCBrushColor(Hdc, RGB(0x60, 0x60, 0x60)); + FrameRect(Hdc, Rect, PhGetStockBrush(DC_BRUSH)); + return S_OK; + } } } @@ -1472,75 +1457,79 @@ HRESULT WINAPI PhDrawThemeBackgroundExHook( { WCHAR className[MAX_PATH]; - // Apply theme to ListView checkboxes - if (iPartId == BP_CHECKBOX /*|| iPartId == BP_RADIOBUTTON*/) + if (PhEnableThemeSupport) { - if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && - PhEqualStringZ(className, VSCLASS_BUTTON, TRUE)) + // Apply theme to ListView checkboxes + if (iPartId == BP_CHECKBOX /*|| iPartId == BP_RADIOBUTTON*/) { - HTHEME darkButtonTheme = PhOpenThemeData(NULL, L"DarkMode_Explorer::Button", 0); - HRESULT retVal = DefaultDrawThemeBackgroundEx(darkButtonTheme ? darkButtonTheme : hTheme, hdc, iPartId, iStateId, pRect, pOptions); - if (darkButtonTheme) - PhCloseThemeData(darkButtonTheme); - return retVal; + if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && + PhEqualStringZ(className, VSCLASS_BUTTON, TRUE)) + { + HTHEME darkButtonTheme = PhOpenThemeData(NULL, L"DarkMode_Explorer::Button", 0); + HRESULT retVal = DefaultDrawThemeBackgroundEx(darkButtonTheme ? darkButtonTheme : hTheme, hdc, iPartId, iStateId, pRect, pOptions); + if (darkButtonTheme) + PhCloseThemeData(darkButtonTheme); + return retVal; + } } - } - // Micro optimization - if ((iPartId == TDLG_PRIMARYPANEL || iPartId == TDLG_FOOTNOTEPANE || iPartId == TDLG_SECONDARYPANEL || iPartId == TDLG_FOOTNOTESEPARATOR || iPartId == TDLG_EXPANDOBUTTON) && - PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_TASKDIALOG, TRUE) - /*|| WindowsVersion < WINDOWS_11 && WindowFromDC(hdc) == NULL*/) - { - switch (iPartId) - { - case TDLG_PRIMARYPANEL: - SetDCBrushColor(hdc, PhThemeWindowBackground2Color); - FillRect(hdc, pRect, PhGetStockBrush(DC_BRUSH)); - return S_OK; - case TDLG_FOOTNOTEPANE: - FillRect(hdc, pRect, PhThemeWindowBackgroundBrush); - return S_OK; - case TDLG_SECONDARYPANEL: - { - FillRect(hdc, pRect, PhThemeWindowBackgroundBrush); - RECT rect = *pRect; - rect.bottom = rect.top + 1; - SetDCBrushColor(hdc, PhThemeWindowForegroundColor); - FillRect(hdc, &rect, PhGetStockBrush(DC_BRUSH)); - PhOffsetRect(&rect, 0, 1); - SetDCBrushColor(hdc, PhThemeWindowBackground2Color); - FillRect(hdc, &rect, PhGetStockBrush(DC_BRUSH)); - return S_OK; - } - case TDLG_FOOTNOTESEPARATOR: + // Micro optimization + if ((iPartId == TDLG_PRIMARYPANEL || iPartId == TDLG_FOOTNOTEPANE || iPartId == TDLG_SECONDARYPANEL || + iPartId == TDLG_FOOTNOTESEPARATOR ||iPartId == TDLG_EXPANDOBUTTON) && + PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_TASKDIALOG, TRUE) + /*|| WindowsVersion < WINDOWS_11 && WindowFromDC(hdc) == NULL*/) { - SetDCBrushColor(hdc, PhThemeWindowForegroundColor); - FillRect(hdc, pRect, PhGetStockBrush(DC_BRUSH)); - RECT rect = *pRect; - rect.top += 1; - SetDCBrushColor(hdc, PhThemeWindowBackground2Color); - FillRect(hdc, &rect, PhGetStockBrush(DC_BRUSH)); - return S_OK; - } - case TDLG_EXPANDOBUTTON: - if (WindowsVersion >= WINDOWS_11) + switch (iPartId) { - // In Windows 11, buttons lack background, making them indistinguishable on dark backgrounds. - // To address this, we invert the button. This technique isn't applicable to Windows 10 as it causes the button's border to appear chipped. - static enum { yes, no, unknown } mustInvertButton = unknown; - if (mustInvertButton == unknown) + case TDLG_PRIMARYPANEL: + SetDCBrushColor(hdc, PhThemeWindowBackground2Color); + FillRect(hdc, pRect, PhGetStockBrush(DC_BRUSH)); + return S_OK; + case TDLG_FOOTNOTEPANE: + FillRect(hdc, pRect, PhThemeWindowBackgroundBrush); + return S_OK; + case TDLG_SECONDARYPANEL: + { + FillRect(hdc, pRect, PhThemeWindowBackgroundBrush); + RECT rect = *pRect; + rect.bottom = rect.top + 1; + SetDCBrushColor(hdc, PhThemeWindowForegroundColor); + FillRect(hdc, &rect, PhGetStockBrush(DC_BRUSH)); + PhOffsetRect(&rect, 0, 1); + SetDCBrushColor(hdc, PhThemeWindowBackground2Color); + FillRect(hdc, &rect, PhGetStockBrush(DC_BRUSH)); + return S_OK; + } + case TDLG_FOOTNOTESEPARATOR: + { + SetDCBrushColor(hdc, PhThemeWindowForegroundColor); + FillRect(hdc, pRect, PhGetStockBrush(DC_BRUSH)); + RECT rect = *pRect; + rect.top += 1; + SetDCBrushColor(hdc, PhThemeWindowBackground2Color); + FillRect(hdc, &rect, PhGetStockBrush(DC_BRUSH)); + return S_OK; + } + case TDLG_EXPANDOBUTTON: + if (WindowsVersion >= WINDOWS_11) { - DefaultDrawThemeBackgroundEx(hTheme, hdc, iPartId, iStateId, pRect, pOptions); - int buttonCenterX = pOptions->rcClip.left + (pOptions->rcClip.right - pOptions->rcClip.left) / 2; - int buttonCenterY = pOptions->rcClip.top + (pOptions->rcClip.bottom - pOptions->rcClip.top) / 2; - COLORREF centerPixel = GetPixel(hdc, buttonCenterX, buttonCenterY); - mustInvertButton = centerPixel == PhThemeWindowTextColor ? no : yes; + // In Windows 11, buttons lack background, making them indistinguishable on dark backgrounds. + // To address this, we invert the button. This technique isn't applicable to Windows 10 as it causes the button's border to appear chipped. + static enum { yes, no, unknown } mustInvertButton = unknown; + if (mustInvertButton == unknown) + { + DefaultDrawThemeBackgroundEx(hTheme, hdc, iPartId, iStateId, pRect, pOptions); + int buttonCenterX = pOptions->rcClip.left + (pOptions->rcClip.right - pOptions->rcClip.left) / 2; + int buttonCenterY = pOptions->rcClip.top + (pOptions->rcClip.bottom - pOptions->rcClip.top) / 2; + COLORREF centerPixel = GetPixel(hdc, buttonCenterX, buttonCenterY); + mustInvertButton = centerPixel == PhThemeWindowTextColor ? no : yes; + } + FillRect(hdc, pRect, PhThemeWindowBackgroundBrush); + if (mustInvertButton == yes) InvertRect(hdc, pRect); + HRESULT retVal = DefaultDrawThemeBackgroundEx(hTheme, hdc, iPartId, iStateId, pRect, pOptions); + if (mustInvertButton == yes) InvertRect(hdc, pRect); + return retVal; } - FillRect(hdc, pRect, PhThemeWindowBackgroundBrush); - if (mustInvertButton == yes) InvertRect(hdc, pRect); - HRESULT retVal = DefaultDrawThemeBackgroundEx(hTheme, hdc, iPartId, iStateId, pRect, pOptions); - if (mustInvertButton == yes) InvertRect(hdc, pRect); - return retVal; } } } @@ -1588,20 +1577,23 @@ HWND PhCreateWindowExHook( if (PhEnableThemeSupport && PhEnableThemeAcrylicWindowSupport) { - PhSetWindowAcrylicCompositionColor(windowHandle, MakeABGRFromCOLORREF(0, RGB(10, 10, 10))); + PhSetWindowAcrylicCompositionColor(windowHandle, MakeABGRFromCOLORREF(0, RGB(10, 10, 10)), TRUE); } } - else if (PhEnableThemeSupport) + else { // Early subclassing of the SysLink control to eliminate blinking during page switches. if (!IS_INTRESOURCE(ClassName) && PhEqualStringZ((PWSTR)ClassName, WC_LINK, TRUE)) { PhInitializeTaskDialogTheme(windowHandle, 0); } - else if (!IS_INTRESOURCE(ClassName) && PhEqualStringZ((PWSTR)ClassName, WC_BUTTON, TRUE) && - PhGetWindowContext(GetAncestor(Parent, GA_ROOT), LONG_MAX)) + else if (PhEnableThemeSupport) { - PhSetControlTheme(windowHandle, L"DarkMode_Explorer"); + if (!IS_INTRESOURCE(ClassName) && PhEqualStringZ((PWSTR)ClassName, WC_BUTTON, TRUE) && + PhGetWindowContext(GetAncestor(Parent, GA_ROOT), LONG_MAX)) + { + PhSetControlTheme(windowHandle, L"DarkMode_Explorer"); + } } } @@ -1615,46 +1607,49 @@ BOOL WINAPI PhSystemParametersInfoHook( _In_ UINT fWinIni ) { - if (uiAction == SPI_GETMENUFADE && pvParam) + if (PhEnableThemeSupport && !PhEnableThemeAnimation) { - *((PBOOL)pvParam) = FALSE; - return TRUE; - } + if (uiAction == SPI_GETMENUFADE && pvParam) + { + *((PBOOL)pvParam) = FALSE; + return TRUE; + } - if (uiAction == SPI_GETCLIENTAREAANIMATION && pvParam) - { - *((PBOOL)pvParam) = FALSE; - return TRUE; - } + if (uiAction == SPI_GETCLIENTAREAANIMATION && pvParam) + { + *((PBOOL)pvParam) = FALSE; + return TRUE; + } - if (uiAction == SPI_GETCOMBOBOXANIMATION && pvParam) - { - *((PBOOL)pvParam) = FALSE; - return TRUE; - } + if (uiAction == SPI_GETCOMBOBOXANIMATION && pvParam) + { + *((PBOOL)pvParam) = FALSE; + return TRUE; + } - if (uiAction == SPI_GETTOOLTIPANIMATION && pvParam) - { - *((PBOOL)pvParam) = FALSE; - return TRUE; - } + if (uiAction == SPI_GETTOOLTIPANIMATION && pvParam) + { + *((PBOOL)pvParam) = FALSE; + return TRUE; + } - if (uiAction == SPI_GETMENUANIMATION && pvParam) - { - *((PBOOL)pvParam) = FALSE; - return TRUE; - } + if (uiAction == SPI_GETMENUANIMATION && pvParam) + { + *((PBOOL)pvParam) = FALSE; + return TRUE; + } - if (uiAction == SPI_GETTOOLTIPFADE && pvParam) - { - *((PBOOL)pvParam) = FALSE; - return TRUE; - } + if (uiAction == SPI_GETTOOLTIPFADE && pvParam) + { + *((PBOOL)pvParam) = FALSE; + return TRUE; + } - if (uiAction == SPI_GETMOUSEVANISH && pvParam) - { - *((PBOOL)pvParam) = FALSE; - return TRUE; + if (uiAction == SPI_GETMOUSEVANISH && pvParam) + { + *((PBOOL)pvParam) = FALSE; + return TRUE; + } } return DefaultSystemParametersInfo(uiAction, uiParam, pvParam, fWinIni); @@ -1720,14 +1715,17 @@ HRESULT WINAPI PhDrawThemeTextHook( _In_ LPCRECT pRect ) { - if ((iPartId == BP_COMMANDLINK /*|| iPartId == BP_RADIOBUTTON*/) && iStateId != PBS_DISABLED) + if (PhEnableThemeSupport) { - WCHAR className[MAX_PATH]; - if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_BUTTON, TRUE) - /*|| WindowsVersion < WINDOWS_11 && WindowFromDC(hdc) == NULL*/) + if ((iPartId == BP_COMMANDLINK /*|| iPartId == BP_RADIOBUTTON*/) && iStateId != PBS_DISABLED) { - DTTOPTS options = { sizeof(DTTOPTS), DTT_TEXTCOLOR, PhThemeWindowTextColor }; - return DefaultDrawThemeTextEx(hTheme, hdc, iPartId, iStateId, pszText, cchText, dwTextFlags, (LPRECT)pRect, &options); + WCHAR className[MAX_PATH]; + if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_BUTTON, TRUE) + /*|| WindowsVersion < WINDOWS_11 && WindowFromDC(hdc) == NULL*/) + { + DTTOPTS options = { sizeof(DTTOPTS), DTT_TEXTCOLOR, PhThemeWindowTextColor }; + return DefaultDrawThemeTextEx(hTheme, hdc, iPartId, iStateId, pszText, cchText, dwTextFlags, (LPRECT)pRect, &options); + } } } @@ -1746,19 +1744,22 @@ HRESULT WINAPI PhDrawThemeTextExHook( _In_ const DTTOPTS* pOptions ) { - if (iPartId == BP_COMMANDLINK) + if (PhEnableThemeSupport) { - WCHAR className[MAX_PATH]; - if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_BUTTON, TRUE) - /*|| WindowsVersion < WINDOWS_11 && WindowFromDC(hdc) == NULL*/) + if (iPartId == BP_COMMANDLINK) { - DTTOPTS options = { sizeof(DTTOPTS) }; - if (pOptions) - options = *pOptions; - options.dwFlags |= DTT_TEXTCOLOR; - DefaultGetThemeColor(hTheme, iPartId, iStateId, TMT_TEXTCOLOR, &options.crText); - options.crText = PhMakeColorBrighter(options.crText, 90); - return DefaultDrawThemeTextEx(hTheme, hdc, iPartId, iStateId, pszText, cchText, dwTextFlags, pRect, &options); + WCHAR className[MAX_PATH]; + if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_BUTTON, TRUE) + /*|| WindowsVersion < WINDOWS_11 && WindowFromDC(hdc) == NULL*/) + { + DTTOPTS options = { sizeof(DTTOPTS) }; + if (pOptions) + options = *pOptions; + options.dwFlags |= DTT_TEXTCOLOR; + DefaultGetThemeColor(hTheme, iPartId, iStateId, TMT_TEXTCOLOR, &options.crText); + options.crText = PhMakeColorBrighter(options.crText, 90); + return DefaultDrawThemeTextEx(hTheme, hdc, iPartId, iStateId, pszText, cchText, dwTextFlags, pRect, &options); + } } } @@ -1777,34 +1778,37 @@ int PhDetoursComCtl32DrawTextW( static COLORREF colLinkNormal = RGB(0, 0 ,0); static COLORREF colLinkHot = RGB(0, 0, 0); static COLORREF colLinkPressed = RGB(0, 0, 0); - HWND WindowHandle; - if ((WindowHandle = WindowFromDC(hdc)) && - (PhIsDarkModeAllowedForWindow(WindowHandle) || PhGetWindowContext(WindowHandle, TASKDIALOG_CONTEXT_TAG))) // HACK + if (PhEnableThemeSupport) { + HWND WindowHandle; WCHAR windowClassName[MAX_PATH]; - GETCLASSNAME_OR_NULL(WindowHandle, windowClassName); - if (PhEqualStringZ(windowClassName, WC_LINK, FALSE)) + + if ((WindowHandle = WindowFromDC(hdc)) && PhIsDarkModeAllowedForWindow(WindowHandle)) // HACK { - if (PhBeginInitOnce(&initOnce)) + GETCLASSNAME_OR_NULL(WindowHandle, windowClassName); + if (PhEqualStringZ(windowClassName, WC_LINK, FALSE)) { - HTHEME hTextTheme = PhOpenThemeData(WindowHandle, VSCLASS_TEXTSTYLE, PhGetWindowDpi(WindowHandle)); - if (hTextTheme) + if (PhBeginInitOnce(&initOnce)) { - PhGetThemeColor(hTextTheme, TEXT_HYPERLINKTEXT, TS_HYPERLINK_NORMAL, TMT_TEXTCOLOR, &colLinkNormal); - PhGetThemeColor(hTextTheme, TEXT_HYPERLINKTEXT, TS_HYPERLINK_HOT, TMT_TEXTCOLOR, &colLinkHot); - PhGetThemeColor(hTextTheme, TEXT_HYPERLINKTEXT, TS_HYPERLINK_PRESSED, TMT_TEXTCOLOR, &colLinkPressed); - PhCloseThemeData(hTextTheme); + HTHEME hTextTheme = PhOpenThemeData(WindowHandle, VSCLASS_TEXTSTYLE, PhGetWindowDpi(WindowHandle)); + if (hTextTheme) + { + PhGetThemeColor(hTextTheme, TEXT_HYPERLINKTEXT, TS_HYPERLINK_NORMAL, TMT_TEXTCOLOR, &colLinkNormal); + PhGetThemeColor(hTextTheme, TEXT_HYPERLINKTEXT, TS_HYPERLINK_HOT, TMT_TEXTCOLOR, &colLinkHot); + PhGetThemeColor(hTextTheme, TEXT_HYPERLINKTEXT, TS_HYPERLINK_PRESSED, TMT_TEXTCOLOR, &colLinkPressed); + PhCloseThemeData(hTextTheme); + } + PhEndInitOnce(&initOnce); } - PhEndInitOnce(&initOnce); - } - COLORREF color = GetTextColor(hdc); + COLORREF color = GetTextColor(hdc); - if (color == colLinkNormal || color == colLinkHot || color == colLinkPressed || - WindowsVersion < WINDOWS_11 && color == RGB(0x00, 0x66, 0xCC)) // on Windows 10 PhGetThemeColor returns 0xFFFFFF for any StateId - { - SetTextColor(hdc, PhMakeColorBrighter(color, 95)); + if (color == colLinkNormal || color == colLinkHot || color == colLinkPressed || + WindowsVersion < WINDOWS_11 && color == RGB(0x00, 0x66, 0xCC)) // on Windows 10 PhGetThemeColor returns 0xFFFFFF for any StateId + { + SetTextColor(hdc, PhMakeColorBrighter(color, 95)); + } } } } @@ -1824,20 +1828,23 @@ HRESULT PhGetThemeColorHook( HRESULT retVal = DefaultGetThemeColor(hTheme, iPartId, iStateId, iPropId, pColor); - if (iPropId == TMT_TEXTCOLOR && iPartId == TDLG_MAININSTRUCTIONPANE) + if (PhEnableThemeSupport) { - if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_TASKDIALOGSTYLE, TRUE) - /*|| WindowsVersion < WINDOWS_11*/) + if (iPropId == TMT_TEXTCOLOR && iPartId == TDLG_MAININSTRUCTIONPANE) { - *pColor = PhMakeColorBrighter(*pColor, 150); // Main header. + if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_TASKDIALOGSTYLE, TRUE) + /*|| WindowsVersion < WINDOWS_11*/) + { + *pColor = PhMakeColorBrighter(*pColor, 150); // Main header. + } } - } - else if (iPropId == TMT_TEXTCOLOR) - { - if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_TASKDIALOGSTYLE, TRUE) - /*|| WindowsVersion < WINDOWS_11*/) + else if (iPropId == TMT_TEXTCOLOR) { - *pColor = PhThemeWindowTextColor; // Text color for check boxes, expanded text, and expander button text. + if (PhGetThemeClass(hTheme, className, RTL_NUMBER_OF(className)) && PhEqualStringZ(className, VSCLASS_TASKDIALOGSTYLE, TRUE) + /*|| WindowsVersion < WINDOWS_11*/) + { + *pColor = PhThemeWindowTextColor; // Text color for check boxes, expanded text, and expander button text. + } } } @@ -1849,10 +1856,13 @@ HTHEME PhOpenNcThemeDataHook( _In_ LPCWSTR pszClassList ) { - if (PhEqualStringZ((PWSTR)pszClassList, VSCLASS_SCROLLBAR, TRUE) && - PhIsDarkModeAllowedForWindow(hwnd)) + if (PhEnableThemeSupport) { - return DefaultOpenNcThemeData(NULL, L"Explorer::ScrollBar"); + if (PhEqualStringZ(pszClassList, VSCLASS_SCROLLBAR, TRUE) && + PhIsDarkModeAllowedForWindow(hwnd)) + { + return DefaultOpenNcThemeData(NULL, L"Explorer::ScrollBar"); + } } return DefaultOpenNcThemeData(hwnd, pszClassList); @@ -1875,7 +1885,10 @@ BOOLEAN CALLBACK PhInitializeTaskDialogTheme( SetWindowDisplayAffinity_Import()(WindowHandle, WDA_EXCLUDEFROMCAPTURE); } - PhInitializeThemeWindowFrame(WindowHandle); + if (PhEnableThemeSupport) + { + PhInitializeThemeWindowFrame(WindowHandle); + } PTASKDIALOG_WINDOW_CONTEXT context = PhAllocateZero(sizeof(TASKDIALOG_WINDOW_CONTEXT)); context->DefaultWindowProc = PhSetWindowProcedure(WindowHandle, ThemeTaskDialogMasterSubclass); @@ -1894,27 +1907,30 @@ BOOLEAN CALLBACK PhInitializeTaskDialogTheme( if (windowHasContext) // HACK return TRUE; - GETCLASSNAME_OR_NULL(WindowHandle, windowClassName); - context = PhAllocateZero(sizeof(TASKDIALOG_COMMON_CONTEXT)); context->DefaultWindowProc = PhSetWindowProcedure(WindowHandle, ThemeTaskDialogMasterSubclass); PhSetWindowContext(WindowHandle, TASKDIALOG_CONTEXT_TAG, context); - if (PhEqualStringZ(windowClassName, WC_BUTTON, FALSE) || - PhEqualStringZ(windowClassName, WC_SCROLLBAR, FALSE)) + if (PhEnableThemeSupport) { - PhSetControlTheme(WindowHandle, L"DarkMode_Explorer"); - } - //else if (PhEqualStringZ(windowClassName, WC_LINK, FALSE)) - //{ - // PhAllowDarkModeForWindow(WindowHandle); // this doesn't work, idk why - //} - else if (PhEqualStringZ(windowClassName, L"DirectUIHWND", FALSE)) - { - //WINDOWPLACEMENT pos = { 0 }; - //GetWindowPlacement(GetParent(WindowHandle), &pos); - PhSetControlTheme(WindowHandle, L"DarkMode_Explorer"); - //SetWindowPlacement(GetParent(WindowHandle), &pos); + GETCLASSNAME_OR_NULL(WindowHandle, windowClassName); + + if (PhEqualStringZ(windowClassName, WC_BUTTON, FALSE) || + PhEqualStringZ(windowClassName, WC_SCROLLBAR, FALSE)) + { + PhSetControlTheme(WindowHandle, L"DarkMode_Explorer"); + } + else if (PhEqualStringZ(windowClassName, WC_LINK, FALSE)) + { + PhAllowDarkModeForWindow(WindowHandle, TRUE); + } + else if (PhEqualStringZ(windowClassName, L"DirectUIHWND", FALSE)) + { + //WINDOWPLACEMENT pos = { 0 }; + //GetWindowPlacement(GetParent(WindowHandle), &pos); + PhSetControlTheme(WindowHandle, L"DarkMode_Explorer"); + //SetWindowPlacement(GetParent(WindowHandle), &pos); + } } return TRUE; @@ -1944,6 +1960,9 @@ LRESULT CALLBACK ThemeTaskDialogMasterSubclass( RECT rect; WCHAR windowClassName[MAX_PATH]; + if (!PhEnableThemeSupport) + return CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam); + SetTextColor(hdc, PhThemeWindowTextColor); // Color for SysLink, which must be set in its parent. if (!context->Painting) @@ -1963,13 +1982,15 @@ LRESULT CALLBACK ThemeTaskDialogMasterSubclass( { LPNMHDR data = (LPNMHDR)lParam; + if (!PhEnableThemeSupport) + return CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam); + if (data->code == NM_CUSTOMDRAW) { LPNMCUSTOMDRAW customDraw = (LPNMCUSTOMDRAW)lParam; WCHAR className[MAX_PATH]; - if (!GetClassName(customDraw->hdr.hwndFrom, className, RTL_NUMBER_OF(className))) - className[0] = UNICODE_NULL; + GETCLASSNAME_OR_NULL(customDraw->hdr.hwndFrom, className); if (PhEqualStringZ(className, WC_BUTTON, FALSE)) { return PhThemeWindowDrawButton(customDraw); @@ -1992,7 +2013,7 @@ LRESULT CALLBACK ThemeTaskDialogMasterSubclass( return CallWindowProc(OldWndProc, hwnd, uMsg, wParam, (LPARAM)myConfig); } - case WM_DESTROY: + case WM_NCDESTROY: { PhSetWindowProcedure(hwnd, OldWndProc); PhRemoveWindowContext(hwnd, TASKDIALOG_CONTEXT_TAG); @@ -2000,7 +2021,8 @@ LRESULT CALLBACK ThemeTaskDialogMasterSubclass( } return CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam); case WM_CTLCOLORDLG: - return (LRESULT)PhThemeWindowBackgroundBrush; // Window background color when the extender resizes upward (Windows 10 only). + // Window background color when the extender resizes upward (Windows 10 only). + return PhEnableThemeSupport ? (LRESULT)PhThemeWindowBackgroundBrush : CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam); } context->Painting++; @@ -2083,17 +2105,15 @@ VOID PhRegisterDetoursHooks( if (!NT_SUCCESS(status = DetourTransactionBegin())) goto CleanupExit; - if (PhEnableThemeSupport || PhEnableThemeAcrylicSupport) { if (!NT_SUCCESS(status = DetourAttach((PVOID)&DefaultDrawThemeBackground, (PVOID)PhDrawThemeBackgroundHook))) goto CleanupExit; if (!NT_SUCCESS(status = DetourAttach((PVOID)&DefaultDrawThemeBackgroundEx, (PVOID)PhDrawThemeBackgroundExHook))) goto CleanupExit; if (!PhEnableThemeAnimation) - { if (!NT_SUCCESS(status = DetourAttach((PVOID)&DefaultSystemParametersInfo, (PVOID)PhSystemParametersInfoHook))) goto CleanupExit; - } + if (!NT_SUCCESS(status = DetourAttach((PVOID)&DefaultDrawThemeText, (PVOID)PhDrawThemeTextHook))) goto CleanupExit; if (!NT_SUCCESS(status = DetourAttach((PVOID)&DefaultDrawThemeTextEx, (PVOID)PhDrawThemeTextExHook))) @@ -2148,38 +2168,18 @@ VOID PhInitializeSuperclassControls( VOID ) { - PhEnableStreamerMode = !!PhGetIntegerSetting(L"EnableStreamerMode"); - if (PhEnableThemeAcrylicSupport && !PhEnableThemeSupport) PhEnableThemeAcrylicSupport = FALSE; - if (PhEnableThemeAcrylicSupport) - PhEnableThemeAcrylicSupport = PhIsThemeTransparencyEnabled(); + //if (PhEnableThemeAcrylicSupport) + //PhEnableThemeAcrylicSupport = PhIsThemeTransparencyEnabled(); // For early TaskDialog with PhStartupParameters.ShowOptions if (!PhThemeWindowBackgroundBrush) PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor); - // If PreferredAppMode is not set, PhShouldAppsUseDarkMode returns current Windows app color mode. - // When app mode set to always dark/light all subsequent calls to PhShouldAppsUseDarkMode always ignore - // the current Windows app color mode and return: - // AppMode = PreferredAppModeDarkAlways always return TRUE - // AppMode = PreferredAppModeLightAlways always return FALSE - // - // It's very convenient because all new opened windows (especially plugin windows) will always have same theme - // even if the system theme was changed while SI is running. To update theme in this case SI restart is required. - PhSetPreferredAppMode(PhEnableThemeSupport ? PreferredAppModeDarkAlways : PreferredAppModeLightAlways); - - if (PhEnableThemeSupport || PhEnableStreamerMode) + // Superclasses and detours now always installing that gives opportunity to flawlessly runtime theme switching. + // If theme is disabled they are just trampolined to original hooked procedures. { - if (WindowsVersion >= WINDOWS_11) - { - PhEnableThemeAcrylicWindowSupport = !!PhGetIntegerSetting(L"EnableThemeAcrylicWindowSupport"); - } - - PhEnableThemeAnimation = !!PhGetIntegerSetting(L"EnableThemeAnimation"); - PhEnableThemeNativeButtons = !!PhGetIntegerSetting(L"EnableThemeNativeButtons"); - PhEnableThemeTabBorders = !!PhGetIntegerSetting(L"EnableThemeTabBorders"); - PhRegisterDialogSuperClass(); PhRegisterMenuSuperClass(); PhRegisterRebarSuperClass(); diff --git a/phlib/emenu.c b/phlib/emenu.c index 3bacbb21633e..d3565e45067d 100644 --- a/phlib/emenu.c +++ b/phlib/emenu.c @@ -612,23 +612,24 @@ VOID PhEMenuToHMenu2( } // Themes - if (WindowsVersion < WINDOWS_10_19H2) - { - if (PhEnableThemeSupport) - { - menuItemInfo.fType |= MFT_OWNERDRAW; - } - } - else - { - if (item->Flags & PH_EMENU_MAINMENU) - { - if (PhEnableThemeSupport) - { - menuItemInfo.fType |= MFT_OWNERDRAW; - } - } - } + // Moved to theme.c PhInitializeWindowThemeMenu. Supports dynamic menu theme switching w/o program restart. (Dart Vanya) + //if (WindowsVersion < WINDOWS_10_19H2) + //{ + // if (PhEnableThemeSupport) + // { + // menuItemInfo.fType |= MFT_OWNERDRAW; + // } + //} + //else + //{ + // if (item->Flags & PH_EMENU_MAINMENU) + // { + // if (PhEnableThemeSupport) + // { + // menuItemInfo.fType |= MFT_OWNERDRAW; + // } + // } + //} InsertMenuItem(MenuHandle, MAXUINT, TRUE, &menuItemInfo); } diff --git a/phlib/guisup.c b/phlib/guisup.c index 60efa9a2f19d..db585deb632c 100644 --- a/phlib/guisup.c +++ b/phlib/guisup.c @@ -81,6 +81,7 @@ static _ShouldAppsUseDarkMode ShouldAppsUseDarkMode_I = NULL; // Win10-RS5 (uxth // Win10 build 17763: AllowDarkModeForApp(BOOL) // Win10 build 18334: SetPreferredAppMode(enum PreferredAppMode) static _SetPreferredAppMode SetPreferredAppMode_I = NULL; +static _FlushMenuThemes FlushMenuThemes_I = NULL; static _GetDpiForMonitor GetDpiForMonitor_I = NULL; // win81+ static _GetDpiForWindow GetDpiForWindow_I = NULL; // win10rs1+ static _GetDpiForSystem GetDpiForSystem_I = NULL; // win10rs1+ @@ -134,6 +135,7 @@ VOID PhGuiSupportInitialization( IsDarkModeAllowedForWindow_I = PhGetDllBaseProcedureAddress(baseAddress, NULL, 137); ShouldAppsUseDarkMode_I = PhGetDllBaseProcedureAddress(baseAddress, NULL, 132); SetPreferredAppMode_I = PhGetDllBaseProcedureAddress(baseAddress, NULL, 135); + FlushMenuThemes_I = PhGetDllBaseProcedureAddress(baseAddress, NULL, 136); } } @@ -449,17 +451,7 @@ BOOLEAN PhIsThemeSupportEnabled( VOID ) { - if (PhGetIntegerSetting(L"EnableThemeSupport")) - { - if (PhGetIntegerSetting(L"EnableThemeUseWindowsTheme")) - return PhShouldAppsUseDarkMode(); - else - return TRUE; - } - else - { - return FALSE; - } + return PhEnableThemeSupport; } BOOLEAN PhSetPreferredAppMode( @@ -469,7 +461,19 @@ BOOLEAN PhSetPreferredAppMode( if (!SetPreferredAppMode_I) return FALSE; - return !!SetPreferredAppMode_I(AppMode); + BOOLEAN retval = !!SetPreferredAppMode_I(AppMode); + PhFlushMenuThemes(); + return retval; +} + +BOOLEAN PhFlushMenuThemes( + VOID + ) +{ + if (!PhFlushMenuThemes) + return FALSE; + + return !!FlushMenuThemes_I(); } // rev from EtwRundown.dll!EtwpLogDPISettingsInfo (dmex) @@ -4553,14 +4557,15 @@ BOOLEAN PhSetWindowCompositionAttribute( BOOLEAN PhSetWindowAcrylicCompositionColor( _In_ HWND WindowHandle, - _In_ ULONG GradientColor + _In_ ULONG GradientColor, + _In_ BOOLEAN Enable ) { ACCENT_POLICY policy = { - ACCENT_ENABLE_ACRYLICBLURBEHIND, - ACCENT_WINDOWS11_LUMINOSITY | ACCENT_BORDER_ALL, - GradientColor, + Enable ? ACCENT_ENABLE_ACRYLICBLURBEHIND : 0, + Enable ? ACCENT_WINDOWS11_LUMINOSITY | ACCENT_BORDER_ALL : 0, + Enable ? GradientColor : 0, 0 }; WINDOWCOMPOSITIONATTRIBUTEDATA attribute = diff --git a/phlib/include/guisup.h b/phlib/include/guisup.h index d2502e3e2341..db1482a49b43 100644 --- a/phlib/include/guisup.h +++ b/phlib/include/guisup.h @@ -252,6 +252,27 @@ PhSetPreferredAppMode( _In_ PreferredAppMode AppMode ); +#define GETCLASSNAME_OR_NULL(WindowHandle, ClassName) if (!GetClassName(WindowHandle, ClassName, RTL_NUMBER_OF(ClassName))) ClassName[0] = UNICODE_NULL + +#define PH_THEME_SET_PREFFEREDAPPMODE(GeneralThemeSetting, UseWindowsThemeSetting) PhSetPreferredAppMode( \ + PhGetIntegerSetting(GeneralThemeSetting) ? \ + PhGetIntegerSetting(UseWindowsThemeSetting) ? PreferredAppModeDarkOnDark : PreferredAppModeDarkAlways : \ + PreferredAppModeLightAlways) + +#define PH_THEME_GET_GENERAL_SWITCH(GeneralThemeSetting) PhGetIntegerSetting(GeneralThemeSetting) && PhShouldAppsUseDarkMode() + +#define HANDLE_COLORSCHEMECHANGE_MESSAGE(wParam, lParam, GeneralThemeSetting, UseWindowsThemeSetting) \ + ((ULONG)wParam == 0 && PhEqualStringZ((PWSTR)lParam, L"ImmersiveColorSet", TRUE) && \ + PhGetIntegerSetting(GeneralThemeSetting) && \ + PhGetIntegerSetting(UseWindowsThemeSetting)) + +PHLIBAPI +BOOLEAN +NTAPI +PhFlushMenuThemes( + VOID + ); + PHLIBAPI BOOLEAN NTAPI @@ -2024,7 +2045,8 @@ BOOLEAN NTAPI PhSetWindowAcrylicCompositionColor( _In_ HWND WindowHandle, - _In_ ULONG GradientColor + _In_ ULONG GradientColor, + _In_ BOOLEAN Enable ); PHLIBAPI @@ -2144,14 +2166,22 @@ PHLIBAPI VOID NTAPI PhInitializeWindowThemeEx( - _In_ HWND WindowHandle + _In_ HWND WindowHandle, + _In_ BOOLEAN EnableThemeSupport ); PHLIBAPI VOID NTAPI -PhReInitializeWindowTheme( - _In_ HWND WindowHandle +PhReInitializeTheme( + BOOLEAN EnableThemeSupport + ); + +PHLIBAPI +VOID +NTAPI +PhReInitializeStreamerMode( + BOOLEAN Enable ); PHLIBAPI @@ -2161,6 +2191,37 @@ PhInitializeThemeWindowFrame( _In_ HWND WindowHandle ); +PHLIBAPI +VOID +NTAPI +PhInitializeThemeWindowFrameEx( + _In_ HWND WindowHandle, + _In_ BOOLEAN EnableThemeSupport + ); + +PHLIBAPI +VOID +NTAPI +PhWindowThemeSetDarkMode( + _In_ HWND WindowHandle, + _In_ BOOLEAN EnableDarkMode + ); + +PHLIBAPI +VOID +NTAPI +PhInitializeWindowThemeMenu( + _In_ HWND WindowHandle, + _In_ BOOLEAN EnableThemeSupport + ); + +PHLIBAPI +BOOLEAN +NTAPI +PhGetAppsUseLightTheme( + VOID + ); + PHLIBAPI HBRUSH NTAPI @@ -2194,13 +2255,6 @@ PhThemeWindowMeasureItem( _In_ PMEASUREITEMSTRUCT DrawInfo ); -PHLIBAPI -VOID -NTAPI -PhInitializeWindowThemeMainMenu( - _In_ HMENU MenuHandle - ); - PHLIBAPI LRESULT CALLBACK diff --git a/phlib/include/guisupp.h b/phlib/include/guisupp.h index 4f914a6030e0..7e7a79ece237 100644 --- a/phlib/include/guisupp.h +++ b/phlib/include/guisupp.h @@ -126,6 +126,10 @@ typedef BOOL(WINAPI* _SetPreferredAppMode)( _In_ PreferredAppMode AppMode ); +typedef BOOL(WINAPI* _FlushMenuThemes)( + VOID + ); + typedef HRESULT (WINAPI* _GetDpiForMonitor)( _In_ HMONITOR hmonitor, _In_ enum MONITOR_DPI_TYPE dpiType, diff --git a/phlib/include/searchbox.h b/phlib/include/searchbox.h index 9942f5f6ac23..df617d4a777c 100644 --- a/phlib/include/searchbox.h +++ b/phlib/include/searchbox.h @@ -35,8 +35,12 @@ PhCreateSearchControlEx( _In_opt_ PCWSTR BannerText, _In_ PCWSTR SearchButtonResource, _In_ PCWSTR SearchButtonActiveResource, - _In_ PCWSTR CaseButtonResource, _In_ PCWSTR RegexButtonResource, + _In_ PCWSTR CaseButtonResource, + _In_ PCWSTR SearchButtonResourceDark, + _In_ PCWSTR SearchButtonActiveResourceDark, + _In_ PCWSTR RegexButtonResourceDark, + _In_ PCWSTR CaseButtonResourceDark, _In_ PCWSTR RegexSetting, _In_ PCWSTR CaseSetting, _In_ PPH_SEARCHCONTROL_CALLBACK Callback, diff --git a/phlib/searchbox.c b/phlib/searchbox.c index 8d424a392f49..4f9e8709b572 100644 --- a/phlib/searchbox.c +++ b/phlib/searchbox.c @@ -65,6 +65,10 @@ typedef struct _PH_SEARCHCONTROL_CONTEXT PCWSTR SearchButtonActiveResource; PCWSTR RegexButtonResource; PCWSTR CaseButtonResource; + PCWSTR SearchButtonResourceDark; + PCWSTR SearchButtonActiveResourceDark; + PCWSTR RegexButtonResourceDark; + PCWSTR CaseButtonResourceDark; PH_SEARCHCONTROL_BUTTON SearchButton; PH_SEARCHCONTROL_BUTTON RegexButton; @@ -225,7 +229,8 @@ VOID PhpSearchControlInitializeImages( Context->SearchButton.ImageIndex = ULONG_MAX; Context->SearchButton.ActiveImageIndex = ULONG_MAX; - bitmap = PhLoadImageFormatFromResource(PhInstanceHandle, Context->SearchButtonResource, L"PNG", PH_IMAGE_FORMAT_TYPE_PNG, Context->ImageWidth, Context->ImageHeight); + bitmap = PhLoadImageFormatFromResource(PhInstanceHandle, PhEnableThemeSupport ? Context->SearchButtonResource : Context->SearchButtonResourceDark, + L"PNG", PH_IMAGE_FORMAT_TYPE_PNG, Context->ImageWidth, Context->ImageHeight); if (bitmap) { Context->SearchButton.ImageIndex = 0; @@ -233,7 +238,8 @@ VOID PhpSearchControlInitializeImages( DeleteBitmap(bitmap); } - bitmap = PhLoadImageFormatFromResource(PhInstanceHandle, Context->SearchButtonActiveResource, L"PNG", PH_IMAGE_FORMAT_TYPE_PNG, Context->ImageWidth, Context->ImageHeight); + bitmap = PhLoadImageFormatFromResource(PhInstanceHandle, PhEnableThemeSupport ? Context->SearchButtonActiveResource : Context->SearchButtonActiveResourceDark, + L"PNG", PH_IMAGE_FORMAT_TYPE_PNG, Context->ImageWidth, Context->ImageHeight); if (bitmap) { Context->SearchButton.ActiveImageIndex = 1; @@ -245,7 +251,8 @@ VOID PhpSearchControlInitializeImages( Context->RegexButton.ImageIndex = ULONG_MAX; Context->RegexButton.ActiveImageIndex = ULONG_MAX; - bitmap = PhLoadImageFormatFromResource(PhInstanceHandle, Context->RegexButtonResource, L"PNG", PH_IMAGE_FORMAT_TYPE_PNG, Context->ImageWidth, Context->ImageHeight); + bitmap = PhLoadImageFormatFromResource(PhInstanceHandle, PhEnableThemeSupport ? Context->RegexButtonResource : Context->RegexButtonResourceDark, + L"PNG", PH_IMAGE_FORMAT_TYPE_PNG, Context->ImageWidth, Context->ImageHeight); if (bitmap) { Context->RegexButton.ImageIndex = 2; @@ -257,7 +264,8 @@ VOID PhpSearchControlInitializeImages( Context->CaseButton.ImageIndex = ULONG_MAX; Context->CaseButton.ActiveImageIndex = ULONG_MAX; - bitmap = PhLoadImageFormatFromResource(PhInstanceHandle, Context->CaseButtonResource, L"PNG", PH_IMAGE_FORMAT_TYPE_PNG, Context->ImageWidth, Context->ImageHeight); + bitmap = PhLoadImageFormatFromResource(PhInstanceHandle, PhEnableThemeSupport ? Context->CaseButtonResource : Context->CaseButtonResourceDark, + L"PNG", PH_IMAGE_FORMAT_TYPE_PNG, Context->ImageWidth, Context->ImageHeight); if (bitmap) { Context->CaseButton.ImageIndex = 3; @@ -1204,6 +1212,10 @@ VOID PhCreateSearchControlEx( _In_ PCWSTR SearchButtonActiveResource, _In_ PCWSTR RegexButtonResource, _In_ PCWSTR CaseButtonResource, + _In_ PCWSTR SearchButtonResourceDark, + _In_ PCWSTR SearchButtonActiveResourceDark, + _In_ PCWSTR RegexButtonResourceDark, + _In_ PCWSTR CaseButtonResourceDark, _In_ PCWSTR RegexSetting, _In_ PCWSTR CaseSetting, _In_ PPH_SEARCHCONTROL_CALLBACK Callback, @@ -1224,6 +1236,10 @@ VOID PhCreateSearchControlEx( context->SearchButtonActiveResource = SearchButtonActiveResource; context->RegexButtonResource = RegexButtonResource; context->CaseButtonResource = CaseButtonResource; + context->SearchButtonResourceDark = SearchButtonResourceDark; + context->SearchButtonActiveResourceDark = SearchButtonActiveResourceDark; + context->RegexButtonResourceDark = RegexButtonResourceDark; + context->CaseButtonResourceDark = CaseButtonResourceDark; context->Callback = Callback; context->CallbackContext = Context; diff --git a/phlib/theme.c b/phlib/theme.c index 7c74ecf2f803..e2867b49579d 100644 --- a/phlib/theme.c +++ b/phlib/theme.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -64,10 +65,6 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( _In_ HWND WindowHandle, _In_opt_ PVOID Context ); -BOOLEAN CALLBACK PhpReInitializeThemeWindowEnumChildWindows( - _In_ HWND WindowHandle, - _In_opt_ PVOID Context - ); LRESULT CALLBACK PhpThemeWindowSubclassProc( _In_ HWND hWnd, @@ -109,14 +106,16 @@ LRESULT CALLBACK PhpThemeWindowACLUISubclassProc( _In_ LPARAM lParam ); +VOID PhThemeUpdateWindowProcedure( + _In_ HWND WindowHandle, + _In_ WNDPROC SubclassProcedure, + _In_ BOOLEAN EnableThemeSupport + ); + // Win10-RS5 (uxtheme.dll ordinal 138) BOOL (WINAPI *ShouldSystemUseDarkMode_I)( VOID ) = NULL; -// Win10-RS5 (uxtheme.dll ordinal 136) -BOOL (WINAPI* FlushMenuThemes_I)( - VOID - ) = NULL; // Win10-RS5 (uxtheme.dll ordinal 139) BOOL (WINAPI *IsDarkModeAllowedForApp_I)( @@ -160,58 +159,68 @@ VOID PhInitializeWindowTheme( _In_ BOOLEAN EnableThemeSupport ) { - PhInitializeThemeWindowFrame(WindowHandle); - - if (!PhThemeWindowBackgroundBrush) + if (EnableThemeSupport && PhEnableThemeSupport) { - //HBRUSH brush = PhThemeWindowBackgroundBrush; - PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor); - //if (brush) DeleteBrush(brush); + PhInitializeWindowThemeEx(WindowHandle, EnableThemeSupport); } +} - if (EnableThemeSupport) - { - WNDPROC defaultWindowProc; +VOID PhInitializeWindowThemeEx( + _In_ HWND WindowHandle, + _In_ BOOLEAN EnableThemeSupport + ) +{ + WCHAR windowClassName[MAX_PATH]; - defaultWindowProc = (WNDPROC)GetWindowLongPtr(WindowHandle, GWLP_WNDPROC); + PhInitializeThemeWindowFrameEx(WindowHandle, EnableThemeSupport); - if (defaultWindowProc != PhpThemeWindowSubclassProc) - { - PhSetWindowContext(WindowHandle, LONG_MAX, defaultWindowProc); - SetWindowLongPtr(WindowHandle, GWLP_WNDPROC, (LONG_PTR)PhpThemeWindowSubclassProc); + { + GETCLASSNAME_OR_NULL(WindowHandle, windowClassName); + if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE)) // HACK for dynamically generated plugin tabs + { if (WindowsVersion >= WINDOWS_10_RS5) { - WCHAR windowClassName[MAX_PATH]; - if (!GetClassName(WindowHandle, windowClassName, RTL_NUMBER_OF(windowClassName))) - windowClassName[0] = UNICODE_NULL; - if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE) || PhEqualStringZ(windowClassName, WC_LISTVIEW, FALSE)) - PhAllowDarkModeForWindow(WindowHandle, TRUE); // HACK for dynamically generated plugin tabs + HWND tooltipWindow = TreeNew_GetTooltips(WindowHandle); + + PhAllowDarkModeForWindow(WindowHandle, EnableThemeSupport); + PhWindowThemeSetDarkMode(WindowHandle, EnableThemeSupport); + if (tooltipWindow) + PhWindowThemeSetDarkMode(tooltipWindow, EnableThemeSupport); + TreeNew_ThemeSupport(WindowHandle, EnableThemeSupport); } } + else + { + PhThemeUpdateWindowProcedure(WindowHandle, PhpThemeWindowSubclassProc, EnableThemeSupport); + + PhInitializeWindowThemeMenu(WindowHandle, EnableThemeSupport); + } PhEnumChildWindows( WindowHandle, 0x1000, PhpThemeWindowEnumChildWindows, - NULL + (PVOID)EnableThemeSupport ); - InvalidateRect(WindowHandle, NULL, FALSE); // HACK + //InvalidateRect(WindowHandle, NULL, FALSE); // HACK + RedrawWindow(WindowHandle, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN /*| RDW_ERASENOW | RDW_UPDATENOW*/); + SendMessage(WindowHandle, WM_THEMECHANGED, 0, 0); // Redraws buttons background in dialogs } - else + //else { //EnableThemeDialogTexture(WindowHandle, ETDT_ENABLETAB); } } -VOID PhInitializeWindowThemeEx( - _In_ HWND WindowHandle +BOOLEAN PhGetAppsUseLightTheme( + VOID ) { static PH_STRINGREF keyPath = PH_STRINGREF_INIT(L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); HANDLE keyHandle; - BOOLEAN enableThemeSupport = FALSE; + BOOLEAN appsUseLightTheme = TRUE; if (NT_SUCCESS(PhOpenKey( &keyHandle, @@ -221,87 +230,79 @@ VOID PhInitializeWindowThemeEx( 0 ))) { - enableThemeSupport = !PhQueryRegistryUlongZ(keyHandle, L"AppsUseLightTheme"); + appsUseLightTheme = !PhQueryRegistryUlongZ(keyHandle, L"AppsUseLightTheme"); NtClose(keyHandle); } - PhInitializeWindowTheme(WindowHandle, enableThemeSupport); + return appsUseLightTheme; } -VOID PhReInitializeWindowTheme( - _In_ HWND WindowHandle +VOID PhReInitializeTheme( + BOOLEAN EnableThemeSupport ) { HWND currentWindow = NULL; - PhInitializeThemeWindowFrame(WindowHandle); - - if (!PhEnableThemeSupport) - return; - - if (!PhThemeWindowBackgroundBrush) + while (currentWindow = FindWindowEx(NULL, currentWindow, NULL, NULL)) { - //HBRUSH brush = PhThemeWindowBackgroundBrush; - PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor); - //if (brush) DeleteBrush(brush); - } + ULONG processID = 0; - PhEnumChildWindows( - WindowHandle, - 0x1000, - PhpReInitializeThemeWindowEnumChildWindows, - NULL - ); + GetWindowThreadProcessId(currentWindow, &processID); - do - { - if (currentWindow = FindWindowEx(NULL, currentWindow, NULL, NULL)) - { - ULONG processID = 0; + WCHAR windowClassName[MAX_PATH]; - GetWindowThreadProcessId(currentWindow, &processID); + if (UlongToHandle(processID) == NtCurrentProcessId()) + { + GETCLASSNAME_OR_NULL(currentWindow, windowClassName); - if (UlongToHandle(processID) == NtCurrentProcessId()) + if (PhEqualStringZ(windowClassName, TOOLTIPS_CLASS, FALSE)) + { + PhWindowThemeSetDarkMode(currentWindow, EnableThemeSupport); // handle tooltips + } + // Update theme on all visible top-level System Informer windows. + else if ((PhGetWindowStyle(currentWindow) & WS_VISIBLE) == WS_VISIBLE) { - WCHAR windowClassName[MAX_PATH]; + dprintf("PhReInitializeTheme: %S\r\n", windowClassName); + + PhInitializeWindowThemeEx(currentWindow, EnableThemeSupport); + } + } + } +} - if (!GetClassName(currentWindow, windowClassName, RTL_NUMBER_OF(windowClassName))) - windowClassName[0] = UNICODE_NULL; +VOID PhReInitializeStreamerMode( + BOOLEAN Enable + ) +{ + HWND currentWindow = NULL; - //dprintf("PhReInitializeWindowTheme: %S\r\n", windowClassName); + while (currentWindow = FindWindowEx(NULL, currentWindow, NULL, NULL)) + { + ULONG processID = 0; - if (currentWindow != WindowHandle) - { - if (PhEqualStringZ(windowClassName, L"#32770", FALSE)) - { - PhEnumChildWindows( - currentWindow, - 0x1000, - PhpReInitializeThemeWindowEnumChildWindows, - NULL - ); - //PhReInitializeWindowTheme(currentWindow); - } + GetWindowThreadProcessId(currentWindow, &processID); - InvalidateRect(currentWindow, NULL, TRUE); - } + if (UlongToHandle(processID) == NtCurrentProcessId()) + { + if ((PhGetWindowStyle(currentWindow) & WS_VISIBLE) == WS_VISIBLE) + { + if (SetWindowDisplayAffinity_Import()) + SetWindowDisplayAffinity_Import()(currentWindow, Enable ? WDA_EXCLUDEFROMCAPTURE : WDA_NONE); } } - } while (currentWindow); - - InvalidateRect(WindowHandle, NULL, FALSE); + } } #define DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 19 -#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE -#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 -#endif -#ifndef DWMWA_CAPTION_COLOR -#define DWMWA_CAPTION_COLOR 35 -#endif -#ifndef DWMWA_SYSTEMBACKDROP_TYPE -#define DWMWA_SYSTEMBACKDROP_TYPE 38 -#endif +//#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +//#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +//#endif +//#ifndef DWMWA_CAPTION_COLOR +//#define DWMWA_CAPTION_COLOR 35 +//#endif +//#ifndef DWMWA_SYSTEMBACKDROP_TYPE +//#define DWMWA_SYSTEMBACKDROP_TYPE 38 +//#endif HRESULT PhSetWindowThemeAttribute( _In_ HWND WindowHandle, @@ -339,42 +340,33 @@ HRESULT PhSetWindowThemeAttribute( VOID PhInitializeThemeWindowFrame( _In_ HWND WindowHandle ) +{ + PhInitializeThemeWindowFrameEx(WindowHandle, PhEnableThemeSupport); +} + +VOID PhInitializeThemeWindowFrameEx( + _In_ HWND WindowHandle, + _In_ BOOLEAN EnableThemeSupport + ) { if (WindowsVersion >= WINDOWS_10_RS5) { - if (PhEnableThemeSupport) + if (FAILED(PhSetWindowThemeAttribute(WindowHandle, DWMWA_USE_IMMERSIVE_DARK_MODE, &(BOOL){ EnableThemeSupport }, sizeof(BOOL)))) { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // { - // if (FAILED(PhSetWindowThemeAttribute(WindowHandle, DWMWA_USE_IMMERSIVE_DARK_MODE, &(BOOL){ FALSE }, sizeof(BOOL)))) - // { - // PhSetWindowThemeAttribute(WindowHandle, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, &(BOOL){ FALSE }, sizeof(BOOL)); - // } - // - // //if (WindowsVersion > WINDOWS_11) - // //{ - // // PhSetWindowThemeAttribute(WindowHandle, DWMWA_CAPTION_COLOR, NULL, 0); - // //} - // } - // break; - //case 1: // Old colors + PhSetWindowThemeAttribute(WindowHandle, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, &(BOOL){ EnableThemeSupport }, sizeof(BOOL)); + } - if (FAILED(PhSetWindowThemeAttribute(WindowHandle, DWMWA_USE_IMMERSIVE_DARK_MODE, &(BOOL){ TRUE }, sizeof(BOOL)))) - { - PhSetWindowThemeAttribute(WindowHandle, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, &(BOOL){ TRUE }, sizeof(BOOL)); - } + if (WindowsVersion >= WINDOWS_11) + { + PhSetWindowThemeAttribute(WindowHandle, DWMWA_CAPTION_COLOR, &(COLORREF){ EnableThemeSupport ? PhThemeWindowBackgroundColor : DWMWA_COLOR_DEFAULT }, + sizeof(COLORREF)); - if (WindowsVersion >= WINDOWS_11) - { - PhSetWindowThemeAttribute(WindowHandle, DWMWA_CAPTION_COLOR, &PhThemeWindowBackgroundColor, sizeof(COLORREF)); - } + PhSetWindowAcrylicCompositionColor(WindowHandle, MakeABGRFromCOLORREF(0, RGB(10, 10, 10)), PhEnableThemeAcrylicWindowSupport); } if (WindowsVersion >= WINDOWS_11_22H2) { - PhSetWindowThemeAttribute(WindowHandle, DWMWA_SYSTEMBACKDROP_TYPE, &(ULONG){ 1 }, sizeof(ULONG)); + PhSetWindowThemeAttribute(WindowHandle, DWMWA_SYSTEMBACKDROP_TYPE, &(ULONG){ EnableThemeSupport ? DWMSBT_NONE : DWMSBT_AUTO }, sizeof(ULONG)); } } } @@ -412,6 +404,35 @@ VOID PhWindowThemeSetDarkMode( } } +VOID PhThemeUpdateWindowProcedure( + _In_ HWND WindowHandle, + _In_ WNDPROC SubclassProcedure, + _In_ BOOLEAN EnableThemeSupport + ) +{ + WNDPROC currentWindowProc; + WNDPROC defaultWindowProc; + + defaultWindowProc = (WNDPROC)PhGetWindowContext(WindowHandle, LONG_MAX); + + if (EnableThemeSupport) + { + if ((currentWindowProc = PhGetWindowProcedure(WindowHandle)) != SubclassProcedure) + { + PhSetWindowContext(WindowHandle, LONG_MAX, currentWindowProc); + PhSetWindowProcedure(WindowHandle, SubclassProcedure); + } + } + else + { + if (defaultWindowProc) + { + PhRemoveWindowContext(WindowHandle, LONG_MAX); + PhSetWindowProcedure(WindowHandle, defaultWindowProc); + } + } +} + HBRUSH PhWindowThemeControlColor( _In_ HWND WindowHandle, _In_ HDC Hdc, @@ -512,139 +533,205 @@ VOID PhWindowThemeMainMenuBorder( } VOID PhInitializeThemeWindowTabControl( - _In_ HWND TabControlWindow + _In_ HWND TabControlWindow, + _In_ BOOLEAN EnableThemeSupport ) { PPHP_THEME_WINDOW_TAB_CONTEXT context; + WNDPROC currentWindowProc; - context = PhAllocateZero(sizeof(PHP_THEME_WINDOW_TAB_CONTEXT)); - context->DefaultWindowProc = (WNDPROC)GetWindowLongPtr(TabControlWindow, GWLP_WNDPROC); - context->CursorPos.x = LONG_MIN; - context->CursorPos.y = LONG_MIN; + context = (PPHP_THEME_WINDOW_TAB_CONTEXT)PhGetWindowContext(TabControlWindow, LONG_MAX); - PhSetWindowContext(TabControlWindow, LONG_MAX, context); - SetWindowLongPtr(TabControlWindow, GWLP_WNDPROC, (LONG_PTR)PhpThemeWindowTabControlWndSubclassProc); + if (EnableThemeSupport) + { + if (!context && (currentWindowProc = PhGetWindowProcedure(TabControlWindow)) != PhpThemeWindowTabControlWndSubclassProc) + { + context = PhAllocateZero(sizeof(PHP_THEME_WINDOW_TAB_CONTEXT)); + context->DefaultWindowProc = currentWindowProc; + context->CursorPos.x = LONG_MIN; + context->CursorPos.y = LONG_MIN; - InvalidateRect(TabControlWindow, NULL, FALSE); + PhSetWindowContext(TabControlWindow, LONG_MAX, context); + PhSetWindowProcedure(TabControlWindow, PhpThemeWindowTabControlWndSubclassProc); + } + } + else + { + if (context && context->DefaultWindowProc) + { + PhRemoveWindowContext(TabControlWindow, LONG_MAX); + PhSetWindowProcedure(TabControlWindow, context->DefaultWindowProc); + PhFree(context); + } + } } VOID PhInitializeThemeWindowGroupBox( - _In_ HWND GroupBoxHandle + _In_ HWND GroupBoxHandle, + _In_ BOOLEAN EnableThemeSupport ) { - WNDPROC groupboxWindowProc; - - groupboxWindowProc = (WNDPROC)GetWindowLongPtr(GroupBoxHandle, GWLP_WNDPROC); - PhSetWindowContext(GroupBoxHandle, LONG_MAX, groupboxWindowProc); - SetWindowLongPtr(GroupBoxHandle, GWLP_WNDPROC, (LONG_PTR)PhpThemeWindowGroupBoxSubclassProc); - - InvalidateRect(GroupBoxHandle, NULL, FALSE); + PhThemeUpdateWindowProcedure(GroupBoxHandle, PhpThemeWindowGroupBoxSubclassProc, EnableThemeSupport); } -VOID PhInitializeWindowThemeMainMenu( - _In_ HMENU MenuHandle +VOID PhInitializeWindowThemeMenu( + _In_ HWND WindowHandle, + _In_ BOOLEAN EnableThemeSupport ) { - MENUINFO menuInfo; + HMENU menuHandle; + + if (menuHandle = GetMenu(WindowHandle)) + { + MENUINFO menuInfo; + MENUITEMINFO menuItemInfo; - if (!PhEnableThemeSupport) - return; + memset(&menuInfo, 0, sizeof(MENUINFO)); + menuInfo.cbSize = sizeof(MENUINFO); + menuInfo.fMask = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS; + menuInfo.hbrBack = EnableThemeSupport ? PhThemeWindowBackgroundBrush : NULL; - memset(&menuInfo, 0, sizeof(MENUINFO)); - menuInfo.cbSize = sizeof(MENUINFO); - menuInfo.fMask = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS; - menuInfo.hbrBack = PhThemeWindowBackgroundBrush; + SetMenuInfo(menuHandle, &menuInfo); - SetMenuInfo(MenuHandle, &menuInfo); + memset(&menuItemInfo, 0, sizeof(MENUITEMINFO)); + menuItemInfo.cbSize = sizeof(MENUITEMINFO); + menuItemInfo.fMask = MIIM_FTYPE; + + for (INT i = 0; i < GetMenuItemCount(menuHandle); i++) + { + GetMenuItemInfo(menuHandle, i, TRUE, &menuItemInfo); + if (EnableThemeSupport) + SetFlag(menuItemInfo.fType, MFT_OWNERDRAW); + else + ClearFlag(menuItemInfo.fType, MFT_OWNERDRAW); + SetMenuItemInfo(menuHandle, i, TRUE, &menuItemInfo); + } + + DrawMenuBar(WindowHandle); + } } VOID PhInitializeWindowThemeListboxControl( - _In_ HWND ListBoxControl + _In_ HWND ListBoxControl, + _In_ BOOLEAN EnableThemeSupport ) { PPHP_THEME_WINDOW_STATUSBAR_CONTEXT context; + WNDPROC currentWindowProc; + + context = (PPHP_THEME_WINDOW_STATUSBAR_CONTEXT)PhGetWindowContext(ListBoxControl, LONG_MAX); - context = PhAllocateZero(sizeof(PHP_THEME_WINDOW_STATUSBAR_CONTEXT)); - context->DefaultWindowProc = (WNDPROC)GetWindowLongPtr(ListBoxControl, GWLP_WNDPROC); - context->CursorPos.x = LONG_MIN; - context->CursorPos.y = LONG_MIN; + if (EnableThemeSupport) + { + if (!context && (currentWindowProc = PhGetWindowProcedure(ListBoxControl)) != PhpThemeWindowListBoxControlSubclassProc) + { + context = PhAllocateZero(sizeof(PHP_THEME_WINDOW_STATUSBAR_CONTEXT)); + context->DefaultWindowProc = currentWindowProc; + context->CursorPos.x = LONG_MIN; + context->CursorPos.y = LONG_MIN; - PhSetWindowContext(ListBoxControl, LONG_MAX, context); - SetWindowLongPtr(ListBoxControl, GWLP_WNDPROC, (LONG_PTR)PhpThemeWindowListBoxControlSubclassProc); + PhSetWindowContext(ListBoxControl, LONG_MAX, context); + PhSetWindowProcedure(ListBoxControl, PhpThemeWindowListBoxControlSubclassProc); + } + } + else + { + if (context && context->DefaultWindowProc) + { + PhRemoveWindowContext(ListBoxControl, LONG_MAX); + PhSetWindowProcedure(ListBoxControl, context->DefaultWindowProc); + PhFree(context); + } + } - InvalidateRect(ListBoxControl, NULL, FALSE); SetWindowPos(ListBoxControl, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED); } VOID PhInitializeWindowThemeComboboxControl( - _In_ HWND ComboBoxControl + _In_ HWND ComboBoxControl, + _In_ BOOLEAN EnableThemeSupport ) { PPHP_THEME_WINDOW_COMBO_CONTEXT context; + WNDPROC currentWindowProc; - context = PhAllocateZero(sizeof(PHP_THEME_WINDOW_COMBO_CONTEXT)); - context->DefaultWindowProc = (WNDPROC)GetWindowLongPtr(ComboBoxControl, GWLP_WNDPROC); - context->ThemeHandle = PhOpenThemeData(ComboBoxControl, VSCLASS_COMBOBOX, PhGetWindowDpi(ComboBoxControl)); - context->CursorPos.x = LONG_MIN; - context->CursorPos.y = LONG_MIN; + context = (PPHP_THEME_WINDOW_COMBO_CONTEXT)PhGetWindowContext(ComboBoxControl, LONG_MAX); - PhSetWindowContext(ComboBoxControl, LONG_MAX, context); - SetWindowLongPtr(ComboBoxControl, GWLP_WNDPROC, (LONG_PTR)PhpThemeWindowComboBoxControlSubclassProc); + if (EnableThemeSupport) + { + if (!context && (currentWindowProc = PhGetWindowProcedure(ComboBoxControl)) != PhpThemeWindowComboBoxControlSubclassProc) + { + context = PhAllocateZero(sizeof(PPHP_THEME_WINDOW_COMBO_CONTEXT)); + context->DefaultWindowProc = currentWindowProc; + context->ThemeHandle = PhOpenThemeData(ComboBoxControl, VSCLASS_COMBOBOX, PhGetWindowDpi(ComboBoxControl)); + context->CursorPos.x = LONG_MIN; + context->CursorPos.y = LONG_MIN; - InvalidateRect(ComboBoxControl, NULL, FALSE); + PhSetWindowContext(ComboBoxControl, LONG_MAX, context); + PhSetWindowProcedure(ComboBoxControl, PhpThemeWindowComboBoxControlSubclassProc); + } + } + else + { + if (context && context->DefaultWindowProc) + { + PhRemoveWindowContext(ComboBoxControl, LONG_MAX); + PhSetWindowProcedure(ComboBoxControl, context->DefaultWindowProc); + if (context->ThemeHandle) + PhCloseThemeData(context->ThemeHandle); + PhFree(context); + } + } } VOID PhInitializeWindowThemeACLUI( - _In_ HWND ACLUIControl + _In_ HWND ACLUIControl, + _In_ BOOLEAN EnableThemeSupport ) { - PhSetWindowContext(ACLUIControl, LONG_MAX, (PVOID)GetWindowLongPtr(ACLUIControl, GWLP_WNDPROC)); - SetWindowLongPtr(ACLUIControl, GWLP_WNDPROC, (LONG_PTR)PhpThemeWindowACLUISubclassProc); - - InvalidateRect(ACLUIControl, NULL, FALSE); + PhThemeUpdateWindowProcedure(ACLUIControl, PhpThemeWindowACLUISubclassProc, EnableThemeSupport); } BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( _In_ HWND WindowHandle, _In_opt_ PVOID Context - ) +) { WCHAR windowClassName[MAX_PATH]; + BOOLEAN enableThemeSupport = !!Context; PhEnumChildWindows( WindowHandle, 0x1000, PhpThemeWindowEnumChildWindows, - NULL - ); + Context + ); - if (PhGetWindowContext(WindowHandle, LONG_MAX)) // HACK + if (enableThemeSupport && PhGetWindowContext(WindowHandle, LONG_MAX)) // HACK return TRUE; - if (!GetClassName(WindowHandle, windowClassName, RTL_NUMBER_OF(windowClassName))) - windowClassName[0] = UNICODE_NULL; + GETCLASSNAME_OR_NULL(WindowHandle, windowClassName); //dprintf("PhpThemeWindowEnumChildWindows: %S\r\n", windowClassName); if (PhEqualStringZ(windowClassName, L"#32770", TRUE)) { - PhInitializeWindowTheme(WindowHandle, TRUE); + PhInitializeWindowThemeEx(WindowHandle, enableThemeSupport); } else if (PhEqualStringZ(windowClassName, WC_BUTTON, FALSE)) { - LONG_PTR style = PhGetWindowStyle(WindowHandle); - if ((style & BS_GROUPBOX) == BS_GROUPBOX) + if ((PhGetWindowStyle(WindowHandle) & BS_GROUPBOX) == BS_GROUPBOX) { - PhInitializeThemeWindowGroupBox(WindowHandle); + PhInitializeThemeWindowGroupBox(WindowHandle, enableThemeSupport); } else // apply theme for CheckBox, Radio (Dart Vanya) { - PhWindowThemeSetDarkMode(WindowHandle, TRUE); + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); } } else if (PhEqualStringZ(windowClassName, WC_TABCONTROL, FALSE)) { - PhInitializeThemeWindowTabControl(WindowHandle); + PhInitializeThemeWindowTabControl(WindowHandle, enableThemeSupport); } else if (PhEqualStringZ(windowClassName, WC_SCROLLBAR, FALSE)) { @@ -656,7 +743,7 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( // PhWindowThemeSetDarkMode(WindowHandle, FALSE); // break; //case 1: // Old colors - PhWindowThemeSetDarkMode(WindowHandle, TRUE); + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); } } else if (PhEqualStringZ(windowClassName, WC_LISTVIEW, FALSE)) @@ -673,17 +760,18 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( // break; //case 1: // Old colors //PhWindowThemeSetDarkMode(WindowHandle, TRUE); - PhAllowDarkModeForWindow(WindowHandle, TRUE); - PhSetControlTheme(WindowHandle, L"DarkMode_ItemsView"); - PhWindowThemeSetDarkMode(tooltipWindow, TRUE); + PhAllowDarkModeForWindow(WindowHandle, enableThemeSupport); + PhSetControlTheme(WindowHandle, enableThemeSupport ? L"DarkMode_ItemsView" : L"Explorer"); + if (tooltipWindow) + PhWindowThemeSetDarkMode(tooltipWindow, enableThemeSupport); } - if (PhEnableThemeListviewBorder) + if (enableThemeSupport && PhEnableThemeListviewBorder) { PhSetWindowStyle(WindowHandle, WS_BORDER, WS_BORDER); PhSetWindowExStyle(WindowHandle, WS_EX_CLIENTEDGE, WS_EX_CLIENTEDGE); } - else + else if (enableThemeSupport) { PhSetWindowStyle(WindowHandle, WS_BORDER, 0); PhSetWindowExStyle(WindowHandle, WS_EX_CLIENTEDGE, 0); @@ -699,9 +787,9 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( // ListView_SetTextColor(WindowHandle, RGB(0x0, 0x0, 0x0)); // break; //case 1: // Old colors - ListView_SetBkColor(WindowHandle, PhThemeWindowBackgroundColor); // RGB(30, 30, 30) - ListView_SetTextBkColor(WindowHandle, PhThemeWindowBackgroundColor); // RGB(30, 30, 30) - ListView_SetTextColor(WindowHandle, PhThemeWindowTextColor); + ListView_SetBkColor(WindowHandle, enableThemeSupport ? PhThemeWindowBackgroundColor : GetSysColor(COLOR_WINDOW)); // RGB(30, 30, 30) + ListView_SetTextBkColor(WindowHandle, enableThemeSupport ? PhThemeWindowBackgroundColor : GetSysColor(COLOR_WINDOW)); // RGB(30, 30, 30) + ListView_SetTextColor(WindowHandle, enableThemeSupport ? PhThemeWindowTextColor : GetSysColor(COLOR_WINDOWTEXT)); } else if (PhEqualStringZ(windowClassName, WC_TREEVIEW, FALSE)) { @@ -709,34 +797,32 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( { HWND tooltipWindow = TreeView_GetToolTips(WindowHandle); - PhWindowThemeSetDarkMode(WindowHandle, TRUE); - PhWindowThemeSetDarkMode(tooltipWindow, TRUE); + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); + PhWindowThemeSetDarkMode(tooltipWindow, enableThemeSupport); } - TreeView_SetBkColor(WindowHandle, PhThemeWindowBackgroundColor);// RGB(30, 30, 30)); + TreeView_SetBkColor(WindowHandle, enableThemeSupport ? PhThemeWindowBackgroundColor : GetSysColor(COLOR_WINDOW));// RGB(30, 30, 30)); //TreeView_SetTextBkColor(WindowHandle, RGB(30, 30, 30)); - TreeView_SetTextColor(WindowHandle, PhThemeWindowTextColor); - //InvalidateRect(WindowHandle, NULL, FALSE); + TreeView_SetTextColor(WindowHandle, enableThemeSupport ? PhThemeWindowTextColor : GetSysColor(COLOR_WINDOWTEXT)); } else if (PhEqualStringZ(windowClassName, L"RICHEDIT50W", FALSE)) { - if (PhEnableThemeListviewBorder) + if (enableThemeSupport && PhEnableThemeListviewBorder) PhSetWindowStyle(WindowHandle, WS_BORDER, WS_BORDER); - else + else if (enableThemeSupport) PhSetWindowStyle(WindowHandle, WS_BORDER, 0); SetWindowPos(WindowHandle, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED); - #define EM_SETBKGNDCOLOR (WM_USER + 67) +#define EM_SETBKGNDCOLOR (WM_USER + 67) //switch (PhpThemeColorMode) //{ //case 0: // New colors // SendMessage(WindowHandle, EM_SETBKGNDCOLOR, 0, RGB(0xff, 0xff, 0xff)); // break; //case 1: // Old colors - SendMessage(WindowHandle, EM_SETBKGNDCOLOR, 0, PhMakeColorBrighter(PhThemeWindowForegroundColor, 2)); // RGB(30, 30, 30) - PhWindowThemeSetDarkMode(WindowHandle, TRUE); - //InvalidateRect(WindowHandle, NULL, FALSE); + SendMessage(WindowHandle, EM_SETBKGNDCOLOR, 0, enableThemeSupport ? PhMakeColorBrighter(PhThemeWindowForegroundColor, 2) : GetSysColor(COLOR_WINDOW)); // RGB(30, 30, 30) + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); } else if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE)) { @@ -751,14 +837,14 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( // PhSetControlTheme(WindowHandle, L""); // break; //case 1: // Old colors - PhWindowThemeSetDarkMode(tooltipWindow, TRUE); - PhWindowThemeSetDarkMode(WindowHandle, TRUE); - PhAllowDarkModeForWindow(WindowHandle, TRUE); + PhWindowThemeSetDarkMode(tooltipWindow, enableThemeSupport); + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); + PhAllowDarkModeForWindow(WindowHandle, enableThemeSupport); } - if (PhEnableThemeListviewBorder) + if (enableThemeSupport && PhEnableThemeListviewBorder) PhSetWindowExStyle(WindowHandle, WS_EX_CLIENTEDGE, WS_EX_CLIENTEDGE); - else + else if (enableThemeSupport) PhSetWindowExStyle(WindowHandle, WS_EX_CLIENTEDGE, 0); SetWindowPos(WindowHandle, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED); @@ -769,9 +855,11 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( // TreeNew_ThemeSupport(WindowHandle, FALSE); // break; //case 1: // Old colors - TreeNew_ThemeSupport(WindowHandle, TRUE); - - //InvalidateRect(WindowHandle, NULL, TRUE); + TreeNew_ThemeSupport(WindowHandle, enableThemeSupport); + } + else if (PhEqualStringZ(windowClassName, WC_HEADER, FALSE)) + { + PhSetControlTheme(WindowHandle, enableThemeSupport ? L"DarkMode_ItemsView" : L"Explorer"); } else if ( PhEqualStringZ(windowClassName, WC_LISTBOX, FALSE) || @@ -786,10 +874,10 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( // PhSetControlTheme(WindowHandle, L"explorer"); // break; //case 1: // Old colors - PhWindowThemeSetDarkMode(WindowHandle, TRUE); + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); } - PhInitializeWindowThemeListboxControl(WindowHandle); + PhInitializeWindowThemeListboxControl(WindowHandle, enableThemeSupport); } else if (PhEqualStringZ(windowClassName, WC_COMBOBOX, FALSE)) { @@ -804,13 +892,13 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( if (info.hwndList) { - PhWindowThemeSetDarkMode(info.hwndList, TRUE); + PhWindowThemeSetDarkMode(info.hwndList, enableThemeSupport); } } //if ((PhGetWindowStyle(WindowHandle) & CBS_DROPDOWNLIST) != CBS_DROPDOWNLIST) { - PhInitializeWindowThemeComboboxControl(WindowHandle); + PhInitializeWindowThemeComboboxControl(WindowHandle, enableThemeSupport); } } else if (PhEqualStringZ(windowClassName, L"CHECKLIST_ACLUI", FALSE)) @@ -823,109 +911,40 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows( // PhSetControlTheme(WindowHandle, L"explorer"); // break; //case 1: // Old colors - PhWindowThemeSetDarkMode(WindowHandle, TRUE); + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); } - PhInitializeWindowThemeACLUI(WindowHandle); + PhInitializeWindowThemeACLUI(WindowHandle, enableThemeSupport); } else if (PhEqualStringZ(windowClassName, WC_EDIT, FALSE)) { // Fix scrollbar on multiline edit (Dart Vanya) - if (GetWindowLongPtr(WindowHandle, GWL_STYLE) & ES_MULTILINE) - { - PhWindowThemeSetDarkMode(WindowHandle, TRUE); - } - } - else if (PhEqualStringZ(windowClassName, WC_LINK, FALSE)) - { - // SysLink theme support (Dart Vanya) - PhAllowDarkModeForWindow(WindowHandle, TRUE); - } - - return TRUE; -} - -BOOLEAN CALLBACK PhpReInitializeThemeWindowEnumChildWindows( - _In_ HWND WindowHandle, - _In_opt_ PVOID Context - ) -{ - WCHAR windowClassName[MAX_PATH]; - - PhEnumChildWindows( - WindowHandle, - 0x1000, - PhpReInitializeThemeWindowEnumChildWindows, - NULL - ); - - if (!GetClassName(WindowHandle, windowClassName, RTL_NUMBER_OF(windowClassName))) - windowClassName[0] = UNICODE_NULL; - - if (PhEqualStringZ(windowClassName, WC_LISTVIEW, FALSE)) - { - if (WindowsVersion >= WINDOWS_10_RS5) + if ((PhGetWindowStyle(WindowHandle) & ES_MULTILINE) == ES_MULTILINE) { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // PhSetControlTheme(WindowHandle, L"explorer"); - // break; - //case 1: // Old colors - PhWindowThemeSetDarkMode(WindowHandle, TRUE); + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); } - - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // ListView_SetBkColor(WindowHandle, RGB(0xff, 0xff, 0xff)); - // ListView_SetTextBkColor(WindowHandle, RGB(0xff, 0xff, 0xff)); - // ListView_SetTextColor(WindowHandle, RGB(0x0, 0x0, 0x0)); - // break; - //case 1: // Old colors - ListView_SetBkColor(WindowHandle, PhThemeWindowBackgroundColor); // RGB(30, 30, 30) - ListView_SetTextBkColor(WindowHandle, PhThemeWindowBackgroundColor); // RGB(30, 30, 30) - ListView_SetTextColor(WindowHandle, PhThemeWindowTextColor); - } - else if (PhEqualStringZ(windowClassName, WC_SCROLLBAR, FALSE)) - { - if (WindowsVersion >= WINDOWS_10_RS5) + else if (PhGetWindowContext(WindowHandle, SHRT_MAX)) // HACK { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // PhSetControlTheme(WindowHandle, L""); - // break; - //case 1: // Old colors - PhWindowThemeSetDarkMode(WindowHandle, TRUE); + SendMessage(WindowHandle, WM_THEMECHANGED, 0, 0); // searchbox.c } } - else if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE)) + else if (PhEqualStringZ(windowClassName, WC_LINK, FALSE)) { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // TreeNew_ThemeSupport(WindowHandle, FALSE); - // PhSetControlTheme(WindowHandle, L""); - // break; - //case 1: // Old colors - TreeNew_ThemeSupport(WindowHandle, TRUE); - PhWindowThemeSetDarkMode(WindowHandle, TRUE); + // SysLink theme support (Dart Vanya) + PhAllowDarkModeForWindow(WindowHandle, enableThemeSupport); } - else if (PhEqualStringZ(windowClassName, WC_EDIT, FALSE)) + else if (PhEqualStringZ(windowClassName, L"DirectUIHWND", FALSE)) // TaskDialog { - SendMessage(WindowHandle, WM_THEMECHANGED, 0, 0); // searchbox.c + PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport); } - InvalidateRect(WindowHandle, NULL, TRUE); - return TRUE; } BOOLEAN PhThemeWindowDrawItem( _In_ HWND WindowHandle, _In_ PDRAWITEMSTRUCT DrawInfo - ) +) { BOOLEAN isGrayed = (DrawInfo->itemState & CDIS_GRAYED) == CDIS_GRAYED; BOOLEAN isChecked = (DrawInfo->itemState & CDIS_CHECKED) == CDIS_CHECKED; @@ -944,306 +963,306 @@ BOOLEAN PhThemeWindowDrawItem( switch (DrawInfo->CtlType) { case ODT_MENU: + { + PPH_EMENU_ITEM menuItemInfo = (PPH_EMENU_ITEM)DrawInfo->itemData; + RECT rect = DrawInfo->rcItem; + LONG dpiValue = PhGetWindowDpi(WindowHandle); + ULONG drawTextFlags = DT_SINGLELINE | DT_NOCLIP; + //HFONT fontHandle; + //HFONT oldFont = NULL; + + if (DrawInfo->itemState & ODS_NOACCEL) { - PPH_EMENU_ITEM menuItemInfo = (PPH_EMENU_ITEM)DrawInfo->itemData; - RECT rect = DrawInfo->rcItem; - LONG dpiValue = PhGetWindowDpi(WindowHandle); - ULONG drawTextFlags = DT_SINGLELINE | DT_NOCLIP; - //HFONT fontHandle; - //HFONT oldFont = NULL; + drawTextFlags |= DT_HIDEPREFIX; + } - if (DrawInfo->itemState & ODS_NOACCEL) - { - drawTextFlags |= DT_HIDEPREFIX; - } + //if (fontHandle = PhCreateMessageFont(dpiValue)) + //{ + // oldFont = SelectFont(DrawInfo->hDC, fontHandle); + //} + // + //FillRect( + // DrawInfo->hDC, + // &DrawInfo->rcItem, + // CreateSolidBrush(RGB(0, 0, 0)) + // ); + //SetTextColor(DrawInfo->hDC, RGB(0xff, 0xff, 0xff)); - //if (fontHandle = PhCreateMessageFont(dpiValue)) - //{ - // oldFont = SelectFont(DrawInfo->hDC, fontHandle); - //} - // - //FillRect( - // DrawInfo->hDC, - // &DrawInfo->rcItem, - // CreateSolidBrush(RGB(0, 0, 0)) - // ); - //SetTextColor(DrawInfo->hDC, RGB(0xff, 0xff, 0xff)); + if (DrawInfo->itemState & ODS_HOTLIGHT) + { + SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); + SetDCBrushColor(DrawInfo->hDC, PhThemeWindowHighlightColor); + FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); + } + else if (isDisabled) + { + SetTextColor(DrawInfo->hDC, GetSysColor(COLOR_GRAYTEXT)); + FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhThemeWindowBackgroundBrush); + } + else if (isSelected) + { + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); + // SetDCBrushColor(DrawInfo->hDC, PhThemeWindowBackgroundColor); + // break; - if (DrawInfo->itemState & ODS_HOTLIGHT) - { - SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); - SetDCBrushColor(DrawInfo->hDC, PhThemeWindowHighlightColor); - FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - } - else if (isDisabled) - { - SetTextColor(DrawInfo->hDC, GetSysColor(COLOR_GRAYTEXT)); - FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhThemeWindowBackgroundBrush); - } - else if (isSelected) - { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); - // SetDCBrushColor(DrawInfo->hDC, PhThemeWindowBackgroundColor); - // break; + SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); + SetDCBrushColor(DrawInfo->hDC, PhThemeWindowHighlightColor); + FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); + } + else + { + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // SetTextColor(DrawInfo->hDC, GetSysColor(COLOR_WINDOWTEXT)); + // SetDCBrushColor(DrawInfo->hDC, RGB(0xff, 0xff, 0xff)); + // FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); + // break; - SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); - SetDCBrushColor(DrawInfo->hDC, PhThemeWindowHighlightColor); - FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - } - else - { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // SetTextColor(DrawInfo->hDC, GetSysColor(COLOR_WINDOWTEXT)); - // SetDCBrushColor(DrawInfo->hDC, RGB(0xff, 0xff, 0xff)); - // FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - // break; + SetTextColor(DrawInfo->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); + FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhThemeWindowBackgroundBrush); + } - SetTextColor(DrawInfo->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); - FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhThemeWindowBackgroundBrush); - } + if (isChecked) + { + static PH_STRINGREF menuCheckText = PH_STRINGREF_INIT(L"\u2713"); + COLORREF oldTextColor; - if (isChecked) - { - static PH_STRINGREF menuCheckText = PH_STRINGREF_INIT(L"\u2713"); - COLORREF oldTextColor; - - //HFONT marlettFontHandle = CreateFont( - // 0, 0, 0, 0, - // FW_DONTCARE, - // FALSE, - // FALSE, - // FALSE, - // DEFAULT_CHARSET, - // OUT_OUTLINE_PRECIS, - // CLIP_DEFAULT_PRECIS, - // CLEARTYPE_QUALITY, - // VARIABLE_PITCH, - // L"Arial Unicode MS" - // ); - - oldTextColor = SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); - - DrawInfo->rcItem.left += PhGetDpi(8, dpiValue); - DrawInfo->rcItem.top += PhGetDpi(3, dpiValue); - DrawText( - DrawInfo->hDC, - menuCheckText.Buffer, - (UINT)menuCheckText.Length / sizeof(WCHAR), - &DrawInfo->rcItem, - DT_VCENTER | DT_NOCLIP - ); - DrawInfo->rcItem.left -= PhGetDpi(8, dpiValue); - DrawInfo->rcItem.top -= PhGetDpi(3, dpiValue); + //HFONT marlettFontHandle = CreateFont( + // 0, 0, 0, 0, + // FW_DONTCARE, + // FALSE, + // FALSE, + // FALSE, + // DEFAULT_CHARSET, + // OUT_OUTLINE_PRECIS, + // CLIP_DEFAULT_PRECIS, + // CLEARTYPE_QUALITY, + // VARIABLE_PITCH, + // L"Arial Unicode MS" + // ); - SetTextColor(DrawInfo->hDC, oldTextColor); - } + oldTextColor = SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); - if (menuItemInfo->Flags & PH_EMENU_SEPARATOR) - { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // SetDCBrushColor(DrawInfo->hDC, RGB(0xff, 0xff, 0xff)); - // FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - // break; - //case 1: // Old colors - //SetDCBrushColor(DrawInfo->hDC, PhThemeWindowBackgroundColor); // PhThemeWindowForegroundColor - FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhThemeWindowBackgroundBrush); - - //DrawInfo->rcItem.top += PhGetDpi(1, dpiValue); - //DrawInfo->rcItem.bottom -= PhGetDpi(2, dpiValue); - //DrawFocusRect(drawInfo->hDC, &drawInfo->rcItem); - - // +5 font margin, +1 extra padding - //INT cxMenuCheck = GetSystemMetrics(SM_CXMENUCHECK) + (GetSystemMetrics(SM_CXEDGE) * 2) + 5 + 1; - INT cyEdge = PhGetSystemMetrics(SM_CYEDGE, dpiValue); - // - //SetRect( - // &DrawInfo->rcItem, - // DrawInfo->rcItem.left + cxMenuCheck, // 25 - // DrawInfo->rcItem.top + cyEdge, - // DrawInfo->rcItem.right, - // DrawInfo->rcItem.bottom - cyEdge - // ); - - SetDCBrushColor(DrawInfo->hDC, RGB(0x5f, 0x5f, 0x5f)); - SelectBrush(DrawInfo->hDC, PhGetStockBrush(DC_BRUSH)); - PatBlt(DrawInfo->hDC, DrawInfo->rcItem.left, DrawInfo->rcItem.top + cyEdge, DrawInfo->rcItem.right - DrawInfo->rcItem.left, 1, PATCOPY); + DrawInfo->rcItem.left += PhGetDpi(8, dpiValue); + DrawInfo->rcItem.top += PhGetDpi(3, dpiValue); + DrawText( + DrawInfo->hDC, + menuCheckText.Buffer, + (UINT)menuCheckText.Length / sizeof(WCHAR), + &DrawInfo->rcItem, + DT_VCENTER | DT_NOCLIP + ); + DrawInfo->rcItem.left -= PhGetDpi(8, dpiValue); + DrawInfo->rcItem.top -= PhGetDpi(3, dpiValue); - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // SetDCBrushColor(DrawInfo->hDC, RGB(0xff, 0xff, 0xff)); - // FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - // break; - //case 1: // Old colors - // SetDCBrushColor(DrawInfo->hDC, RGB(78, 78, 78)); - // FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - // break; - //} + SetTextColor(DrawInfo->hDC, oldTextColor); + } - //DrawEdge(drawInfo->hDC, &drawInfo->rcItem, BDR_RAISEDINNER, BF_TOP); - } - else - { - PH_STRINGREF part = { 0 }; - PH_STRINGREF firstPart = { 0 }; - PH_STRINGREF secondPart = { 0 }; + if (menuItemInfo->Flags & PH_EMENU_SEPARATOR) + { + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // SetDCBrushColor(DrawInfo->hDC, RGB(0xff, 0xff, 0xff)); + // FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); + // break; + //case 1: // Old colors + //SetDCBrushColor(DrawInfo->hDC, PhThemeWindowBackgroundColor); // PhThemeWindowForegroundColor + FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhThemeWindowBackgroundBrush); - PhInitializeStringRefLongHint(&part, menuItemInfo->Text); - PhSplitStringRefAtLastChar(&part, L'\b', &firstPart, &secondPart); + //DrawInfo->rcItem.top += PhGetDpi(1, dpiValue); + //DrawInfo->rcItem.bottom -= PhGetDpi(2, dpiValue); + //DrawFocusRect(drawInfo->hDC, &drawInfo->rcItem); - //SetDCBrushColor(DrawInfo->hDC, PhThemeWindowForegroundColor); - //FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); + // +5 font margin, +1 extra padding + //INT cxMenuCheck = GetSystemMetrics(SM_CXMENUCHECK) + (GetSystemMetrics(SM_CXEDGE) * 2) + 5 + 1; + INT cyEdge = PhGetSystemMetrics(SM_CYEDGE, dpiValue); + // + //SetRect( + // &DrawInfo->rcItem, + // DrawInfo->rcItem.left + cxMenuCheck, // 25 + // DrawInfo->rcItem.top + cyEdge, + // DrawInfo->rcItem.right, + // DrawInfo->rcItem.bottom - cyEdge + // ); - if (menuItemInfo->Bitmap) - { - HDC bufferDc; - BLENDFUNCTION blendFunction; + SetDCBrushColor(DrawInfo->hDC, RGB(0x5f, 0x5f, 0x5f)); + SelectBrush(DrawInfo->hDC, PhGetStockBrush(DC_BRUSH)); + PatBlt(DrawInfo->hDC, DrawInfo->rcItem.left, DrawInfo->rcItem.top + cyEdge, DrawInfo->rcItem.right - DrawInfo->rcItem.left, 1, PATCOPY); - blendFunction.BlendOp = AC_SRC_OVER; - blendFunction.BlendFlags = 0; - blendFunction.SourceConstantAlpha = 255; - blendFunction.AlphaFormat = AC_SRC_ALPHA; + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // SetDCBrushColor(DrawInfo->hDC, RGB(0xff, 0xff, 0xff)); + // FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); + // break; + //case 1: // Old colors + // SetDCBrushColor(DrawInfo->hDC, RGB(78, 78, 78)); + // FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); + // break; + //} - bufferDc = CreateCompatibleDC(DrawInfo->hDC); - SelectBitmap(bufferDc, menuItemInfo->Bitmap); + //DrawEdge(drawInfo->hDC, &drawInfo->rcItem, BDR_RAISEDINNER, BF_TOP); + } + else + { + PH_STRINGREF part = { 0 }; + PH_STRINGREF firstPart = { 0 }; + PH_STRINGREF secondPart = { 0 }; - GdiAlphaBlend( - DrawInfo->hDC, - DrawInfo->rcItem.left + 4, - DrawInfo->rcItem.top + 4, - PhGetSystemMetrics(SM_CXSMICON, dpiValue), - PhGetSystemMetrics(SM_CYSMICON, dpiValue), - bufferDc, - 0, - 0, - PhGetSystemMetrics(SM_CXSMICON, dpiValue), - PhGetSystemMetrics(SM_CYSMICON, dpiValue), - blendFunction - ); + PhInitializeStringRefLongHint(&part, menuItemInfo->Text); + PhSplitStringRefAtLastChar(&part, L'\b', &firstPart, &secondPart); - DeleteDC(bufferDc); - } + //SetDCBrushColor(DrawInfo->hDC, PhThemeWindowForegroundColor); + //FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - DrawInfo->rcItem.left += PhGetDpi(25, dpiValue); - DrawInfo->rcItem.right -= PhGetDpi(25, dpiValue); + if (menuItemInfo->Bitmap) + { + HDC bufferDc; + BLENDFUNCTION blendFunction; - if ((menuItemInfo->Flags & PH_EMENU_MAINMENU) == PH_EMENU_MAINMENU) - { - if (firstPart.Length) - { - DrawText( - DrawInfo->hDC, - firstPart.Buffer, - (UINT)firstPart.Length / sizeof(WCHAR), - &DrawInfo->rcItem, - DT_LEFT | DT_SINGLELINE | DT_CENTER | DT_VCENTER | drawTextFlags - ); - } - } - else + blendFunction.BlendOp = AC_SRC_OVER; + blendFunction.BlendFlags = 0; + blendFunction.SourceConstantAlpha = 255; + blendFunction.AlphaFormat = AC_SRC_ALPHA; + + bufferDc = CreateCompatibleDC(DrawInfo->hDC); + SelectBitmap(bufferDc, menuItemInfo->Bitmap); + + GdiAlphaBlend( + DrawInfo->hDC, + DrawInfo->rcItem.left + 4, + DrawInfo->rcItem.top + 4, + PhGetSystemMetrics(SM_CXSMICON, dpiValue), + PhGetSystemMetrics(SM_CYSMICON, dpiValue), + bufferDc, + 0, + 0, + PhGetSystemMetrics(SM_CXSMICON, dpiValue), + PhGetSystemMetrics(SM_CYSMICON, dpiValue), + blendFunction + ); + + DeleteDC(bufferDc); + } + + DrawInfo->rcItem.left += PhGetDpi(25, dpiValue); + DrawInfo->rcItem.right -= PhGetDpi(25, dpiValue); + + if ((menuItemInfo->Flags & PH_EMENU_MAINMENU) == PH_EMENU_MAINMENU) + { + if (firstPart.Length) { - if (firstPart.Length) - { - DrawText( - DrawInfo->hDC, - firstPart.Buffer, - (UINT)firstPart.Length / sizeof(WCHAR), - &DrawInfo->rcItem, - DT_LEFT | DT_VCENTER | drawTextFlags - ); - } + DrawText( + DrawInfo->hDC, + firstPart.Buffer, + (UINT)firstPart.Length / sizeof(WCHAR), + &DrawInfo->rcItem, + DT_LEFT | DT_SINGLELINE | DT_CENTER | DT_VCENTER | drawTextFlags + ); } - - if (secondPart.Length) + } + else + { + if (firstPart.Length) { DrawText( DrawInfo->hDC, - secondPart.Buffer, - (UINT)secondPart.Length / sizeof(WCHAR), + firstPart.Buffer, + (UINT)firstPart.Length / sizeof(WCHAR), &DrawInfo->rcItem, - DT_RIGHT | DT_VCENTER | drawTextFlags - ); + DT_LEFT | DT_VCENTER | drawTextFlags + ); } } - //if (oldFont) - //{ - // SelectFont(DrawInfo->hDC, oldFont); - //} - - if (menuItemInfo->Items && menuItemInfo->Items->Count && (menuItemInfo->Flags & PH_EMENU_MAINMENU) != PH_EMENU_MAINMENU) + if (secondPart.Length) { - HTHEME themeHandle; + DrawText( + DrawInfo->hDC, + secondPart.Buffer, + (UINT)secondPart.Length / sizeof(WCHAR), + &DrawInfo->rcItem, + DT_RIGHT | DT_VCENTER | drawTextFlags + ); + } + } - if (themeHandle = PhOpenThemeData(DrawInfo->hwndItem, VSCLASS_MENU, dpiValue)) - { - //if (IsThemeBackgroundPartiallyTransparent(themeHandle, MENU_POPUPSUBMENU, isDisabled ? MSM_DISABLED : MSM_NORMAL)) - // DrawThemeParentBackground(DrawInfo->hwndItem, DrawInfo->hDC, NULL); + //if (oldFont) + //{ + // SelectFont(DrawInfo->hDC, oldFont); + //} - rect.left = rect.right - PhGetDpi(25, dpiValue); + if (menuItemInfo->Items && menuItemInfo->Items->Count && (menuItemInfo->Flags & PH_EMENU_MAINMENU) != PH_EMENU_MAINMENU) + { + HTHEME themeHandle; - PhDrawThemeBackground( - themeHandle, - DrawInfo->hDC, - MENU_POPUPSUBMENU, - isDisabled ? MSM_DISABLED : MSM_NORMAL, - &rect, - NULL - ); + if (themeHandle = PhOpenThemeData(DrawInfo->hwndItem, VSCLASS_MENU, dpiValue)) + { + //if (IsThemeBackgroundPartiallyTransparent(themeHandle, MENU_POPUPSUBMENU, isDisabled ? MSM_DISABLED : MSM_NORMAL)) + // DrawThemeParentBackground(DrawInfo->hwndItem, DrawInfo->hDC, NULL); - PhCloseThemeData(themeHandle); - } + rect.left = rect.right - PhGetDpi(25, dpiValue); + + PhDrawThemeBackground( + themeHandle, + DrawInfo->hDC, + MENU_POPUPSUBMENU, + isDisabled ? MSM_DISABLED : MSM_NORMAL, + &rect, + NULL + ); + + PhCloseThemeData(themeHandle); } + } - ExcludeClipRect(DrawInfo->hDC, rect.left, rect.top, rect.right, rect.bottom); // exclude last + ExcludeClipRect(DrawInfo->hDC, rect.left, rect.top, rect.right, rect.bottom); // exclude last - //if (fontHandle) - //{ - // DeleteFont(fontHandle); - //} + //if (fontHandle) + //{ + // DeleteFont(fontHandle); + //} - return TRUE; - } + return TRUE; + } case ODT_COMBOBOX: - { - SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); - SetDCBrushColor(DrawInfo->hDC, isSelected ? PhMakeColorBrighter(PhThemeWindowBackground2Color, 15) : PhThemeWindowForegroundColor); // RGB(80, 80, 80) - FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - - INT length = ComboBox_GetLBTextLen(DrawInfo->hwndItem, DrawInfo->itemID); + { + SetTextColor(DrawInfo->hDC, PhThemeWindowTextColor); + SetDCBrushColor(DrawInfo->hDC, isSelected ? PhMakeColorBrighter(PhThemeWindowBackground2Color, 15) : PhThemeWindowForegroundColor); // RGB(80, 80, 80) + FillRect(DrawInfo->hDC, &DrawInfo->rcItem, PhGetStockBrush(DC_BRUSH)); - if (length == CB_ERR) - break; + INT length = ComboBox_GetLBTextLen(DrawInfo->hwndItem, DrawInfo->itemID); - if (length < MAX_PATH) - { - WCHAR comboText[MAX_PATH] = L""; + if (length == CB_ERR) + break; - if (ComboBox_GetLBText(DrawInfo->hwndItem, DrawInfo->itemID, comboText) == CB_ERR) - break; + if (length < MAX_PATH) + { + WCHAR comboText[MAX_PATH] = L""; - RECT rect = DrawInfo->rcItem; - rect.left += 2; + if (ComboBox_GetLBText(DrawInfo->hwndItem, DrawInfo->itemID, comboText) == CB_ERR) + break; - DrawText( - DrawInfo->hDC, - comboText, - (UINT)PhCountStringZ(comboText), - &rect, - DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE | DT_VCENTER - ); - } + RECT rect = DrawInfo->rcItem; + rect.left += 2; - return TRUE; + DrawText( + DrawInfo->hDC, + comboText, + (UINT)PhCountStringZ(comboText), + &rect, + DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE | DT_VCENTER + ); } - break; + + return TRUE; + } + break; } return FALSE; @@ -1252,7 +1271,7 @@ BOOLEAN PhThemeWindowDrawItem( BOOLEAN PhThemeWindowMeasureItem( _In_ HWND WindowHandle, _In_ PMEASUREITEMSTRUCT DrawInfo - ) +) { if (DrawInfo->CtlType == ODT_MENU) { @@ -1442,7 +1461,7 @@ VOID PhThemeDrawButtonIcon( _In_ HICON ButtonIcon, _In_ PRECT ButtonRect, _In_ LONG WindowDpi - ) +) { BOOL result; ICONINFO iconInfo; @@ -1486,7 +1505,7 @@ VOID PhThemeDrawButtonIcon( 0, NULL, DI_NORMAL - ); + ); if (!result) // HACK { @@ -1504,7 +1523,7 @@ VOID PhThemeDrawButtonIcon( ButtonRect->top + ((ButtonRect->bottom - ButtonRect->top) - height) / 2, ILD_NORMAL, FALSE - ); + ); ButtonRect->left += PhGetDpi(5, WindowDpi); } @@ -1513,7 +1532,7 @@ VOID PhThemeDrawButtonIcon( LRESULT CALLBACK PhThemeWindowDrawButton( _In_ LPNMCUSTOMDRAW DrawInfo - ) +) { LONG_PTR buttonStyle; @@ -1540,299 +1559,299 @@ LRESULT CALLBACK PhThemeWindowDrawButton( switch (DrawInfo->dwDrawStage) { case CDDS_PREPAINT: - { - PPH_STRING buttonText; - HICON buttonIcon; - LONG dpiValue; + { + PPH_STRING buttonText; + HICON buttonIcon; + LONG dpiValue; - BOOLEAN isCheckbox = (buttonStyle & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX || (buttonStyle & BS_AUTO3STATE) == BS_AUTO3STATE; - BOOLEAN isRadio = (buttonStyle & BS_AUTORADIOBUTTON) == BS_AUTORADIOBUTTON; + BOOLEAN isCheckbox = (buttonStyle & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX || (buttonStyle & BS_AUTO3STATE) == BS_AUTO3STATE; + BOOLEAN isRadio = (buttonStyle & BS_AUTORADIOBUTTON) == BS_AUTORADIOBUTTON; - if (!isCheckbox && !isRadio && PhEnableThemeNativeButtons && !PhEnableThemeAcrylicWindowSupport) - return CDRF_DODEFAULT; + if (!isCheckbox && !isRadio && PhEnableThemeNativeButtons && !PhEnableThemeAcrylicWindowSupport) + return CDRF_DODEFAULT; - dpiValue = PhGetWindowDpi(DrawInfo->hdr.hwndFrom); - buttonText = PhGetWindowText(DrawInfo->hdr.hwndFrom); + dpiValue = PhGetWindowDpi(DrawInfo->hdr.hwndFrom); + buttonText = PhGetWindowText(DrawInfo->hdr.hwndFrom); - if (!(buttonIcon = Static_GetIcon(DrawInfo->hdr.hwndFrom, 0))) - buttonIcon = (HICON)SendMessage(DrawInfo->hdr.hwndFrom, BM_GETIMAGE, IMAGE_ICON, 0); + if (!(buttonIcon = Static_GetIcon(DrawInfo->hdr.hwndFrom, 0))) + buttonIcon = (HICON)SendMessage(DrawInfo->hdr.hwndFrom, BM_GETIMAGE, IMAGE_ICON, 0); - // Add support for disabled and tristate checkboxes, support for radio with multiline (ex. TaskDialog) (Dart Vanya) - if (isCheckbox || isRadio) - { - INT state = isCheckbox ? CBS_UNCHECKEDNORMAL : RBS_UNCHECKEDNORMAL; - HTHEME themeHandle; + // Add support for disabled and tristate checkboxes, support for radio with multiline (ex. TaskDialog) (Dart Vanya) + if (isCheckbox || isRadio) + { + INT state = isCheckbox ? CBS_UNCHECKEDNORMAL : RBS_UNCHECKEDNORMAL; + HTHEME themeHandle; - isChecked = Button_GetCheck(DrawInfo->hdr.hwndFrom) & BST_CHECKED; - isMixed = Button_GetCheck(DrawInfo->hdr.hwndFrom) & BST_INDETERMINATE; + isChecked = Button_GetCheck(DrawInfo->hdr.hwndFrom) & BST_CHECKED; + isMixed = Button_GetCheck(DrawInfo->hdr.hwndFrom) & BST_INDETERMINATE; - if (isCheckbox) - { - if (isDisabled) - state = isChecked ? CBS_CHECKEDDISABLED : isMixed ? CBS_MIXEDDISABLED : CBS_UNCHECKEDDISABLED; - else if (isSelected) - state = isChecked ? CBS_CHECKEDPRESSED : isMixed ? CBS_MIXEDPRESSED : CBS_UNCHECKEDPRESSED; - else if (isHighlighted) - state = isChecked ? CBS_CHECKEDHOT : isMixed ? CBS_MIXEDHOT : CBS_UNCHECKEDHOT; - else - state = isChecked ? CBS_CHECKEDNORMAL : isMixed ? CBS_MIXEDNORMAL : CBS_UNCHECKEDNORMAL; - } + if (isCheckbox) + { + if (isDisabled) + state = isChecked ? CBS_CHECKEDDISABLED : isMixed ? CBS_MIXEDDISABLED : CBS_UNCHECKEDDISABLED; + else if (isSelected) + state = isChecked ? CBS_CHECKEDPRESSED : isMixed ? CBS_MIXEDPRESSED : CBS_UNCHECKEDPRESSED; + else if (isHighlighted) + state = isChecked ? CBS_CHECKEDHOT : isMixed ? CBS_MIXEDHOT : CBS_UNCHECKEDHOT; + else + state = isChecked ? CBS_CHECKEDNORMAL : isMixed ? CBS_MIXEDNORMAL : CBS_UNCHECKEDNORMAL; + } + else + { + if (isDisabled) + state = isChecked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED; + else if (isSelected) + state = isChecked ? RBS_CHECKEDPRESSED : RBS_UNCHECKEDPRESSED; + else if (isHighlighted) + state = isChecked ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT; else + state = isChecked ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL; + } + + if (buttonIcon) + { + if (isSelected || isChecked) { - if (isDisabled) - state = isChecked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED; - else if (isSelected) - state = isChecked ? RBS_CHECKEDPRESSED : RBS_UNCHECKEDPRESSED; - else if (isHighlighted) - state = isChecked ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT; - else - state = isChecked ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL; + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // //SetTextColor(DrawInfo->hdc, RGB(0, 0, 0xff)); + // SetDCBrushColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHT)); + // break; + //case 1: // Old colors + SetTextColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetDCBrushColor(DrawInfo->hdc, PhMakeColorBrighter(PhThemeWindowBackground2Color, 13)); // RGB(78, 78, 78) + FillRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); } - - if (buttonIcon) + else if (isHighlighted) { - if (isSelected || isChecked) - { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // //SetTextColor(DrawInfo->hdc, RGB(0, 0, 0xff)); - // SetDCBrushColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHT)); - // break; - //case 1: // Old colors - SetTextColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetDCBrushColor(DrawInfo->hdc, PhMakeColorBrighter(PhThemeWindowBackground2Color, 13)); // RGB(78, 78, 78) - FillRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); - } - else if (isHighlighted) - { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // //SetTextColor(DrawInfo->hdc, RGB(0, 0, 0xff)); - // SetDCBrushColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHT)); - // break; - //case 1: // Old colors - SetTextColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackground2Color); - FillRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); - } - else - { - SetTextColor(DrawInfo->hdc, !isDisabled ? PhThemeWindowTextColor : RGB(0x9B, 0x9B, 0x9B)); - //SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackgroundColor); // WindowForegroundColor - FillRect(DrawInfo->hdc, &DrawInfo->rc, PhThemeWindowBackgroundBrush); - } - + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // //SetTextColor(DrawInfo->hdc, RGB(0, 0, 0xff)); + // SetDCBrushColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHT)); + // break; + //case 1: // Old colors + SetTextColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackground2Color); - FrameRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); - - PhThemeDrawButtonIcon(DrawInfo, buttonIcon, &bufferRect, dpiValue); + FillRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); } else { - SetBkMode(DrawInfo->hdc, TRANSPARENT); SetTextColor(DrawInfo->hdc, !isDisabled ? PhThemeWindowTextColor : RGB(0x9B, 0x9B, 0x9B)); + //SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackgroundColor); // WindowForegroundColor + FillRect(DrawInfo->hdc, &DrawInfo->rc, PhThemeWindowBackgroundBrush); + } - if (themeHandle = PhOpenThemeData(DrawInfo->hdr.hwndFrom, VSCLASS_BUTTON, dpiValue)) - { - SIZE checkBoxSize = { 0 }; - SIZE textSize = { 0 }; - INT linesCount; + SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackground2Color); + FrameRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); - PhGetThemePartSize( - themeHandle, - DrawInfo->hdc, - isCheckbox ? BP_CHECKBOX : BP_RADIOBUTTON, - state, - &bufferRect, - TS_TRUE, - &checkBoxSize - ); - GetTextExtentPoint32W(DrawInfo->hdc, L"T", 1, &textSize); + PhThemeDrawButtonIcon(DrawInfo, buttonIcon, &bufferRect, dpiValue); + } + else + { + SetBkMode(DrawInfo->hdc, TRANSPARENT); + SetTextColor(DrawInfo->hdc, !isDisabled ? PhThemeWindowTextColor : RGB(0x9B, 0x9B, 0x9B)); + + if (themeHandle = PhOpenThemeData(DrawInfo->hdr.hwndFrom, VSCLASS_BUTTON, dpiValue)) + { + SIZE checkBoxSize = { 0 }; + SIZE textSize = { 0 }; + INT linesCount; + + PhGetThemePartSize( + themeHandle, + DrawInfo->hdc, + isCheckbox ? BP_CHECKBOX : BP_RADIOBUTTON, + state, + &bufferRect, + TS_TRUE, + &checkBoxSize + ); + GetTextExtentPoint32W(DrawInfo->hdc, L"T", 1, &textSize); - bufferRect.left = 0; - bufferRect.right = checkBoxSize.cx; - linesCount = (bufferRect.bottom - bufferRect.top) / textSize.cy; - if (linesCount > 1) - bufferRect.bottom -= textSize.cy * (linesCount - 1); // HACK (very sensitive value) + bufferRect.left = 0; + bufferRect.right = checkBoxSize.cx; + linesCount = (bufferRect.bottom - bufferRect.top) / textSize.cy; + if (linesCount > 1) + bufferRect.bottom -= textSize.cy * (linesCount - 1); // HACK (very sensitive value) + + //if (IsThemeBackgroundPartiallyTransparent(themeHandle, isCheckbox ? BP_CHECKBOX : BP_RADIOBUTTON, state)) + // DrawThemeParentBackground(DrawInfo->hdr.hwndFrom, DrawInfo->hdc, NULL); + + PhDrawThemeBackground( + themeHandle, + DrawInfo->hdc, + isCheckbox ? BP_CHECKBOX : BP_RADIOBUTTON, + state, + &bufferRect, + NULL + ); - //if (IsThemeBackgroundPartiallyTransparent(themeHandle, isCheckbox ? BP_CHECKBOX : BP_RADIOBUTTON, state)) - // DrawThemeParentBackground(DrawInfo->hdr.hwndFrom, DrawInfo->hdc, NULL); + bufferRect = DrawInfo->rc; + bufferRect.left = checkBoxSize.cx + 4; // TNP_ICON_RIGHT_PADDING - PhDrawThemeBackground( - themeHandle, + if (linesCount == 1) + { + DrawText( DrawInfo->hdc, - isCheckbox ? BP_CHECKBOX : BP_RADIOBUTTON, - state, + buttonText->Buffer, + (UINT)buttonText->Length / sizeof(WCHAR), &bufferRect, - NULL - ); - - bufferRect = DrawInfo->rc; - bufferRect.left = checkBoxSize.cx + 4; // TNP_ICON_RIGHT_PADDING - - if (linesCount == 1) - { - DrawText( - DrawInfo->hdc, - buttonText->Buffer, - (UINT)buttonText->Length / sizeof(WCHAR), - &bufferRect, - DT_LEFT | DT_SINGLELINE | DT_VCENTER | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) - ); - } - else - { - DrawText( - DrawInfo->hdc, - buttonText->Buffer, - (UINT)buttonText->Length / sizeof(WCHAR), - &bufferRect, - DT_LEFT | DT_TOP | DT_CALCRECT | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) - ); - - bufferRect.top = (DrawInfo->rc.bottom - DrawInfo->rc.top) / 2 - (bufferRect.bottom - bufferRect.top) / 2 - 1; - bufferRect.bottom = DrawInfo->rc.bottom, bufferRect.right = DrawInfo->rc.right; - - DrawText( - DrawInfo->hdc, - buttonText->Buffer, - (UINT)buttonText->Length / sizeof(WCHAR), - &bufferRect, - DT_LEFT | DT_TOP | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) - ); - } - - if (isKeyboardFocused) - { - DrawText( - DrawInfo->hdc, - buttonText->Buffer, - (UINT)buttonText->Length / sizeof(WCHAR), - &bufferRect, - DT_LEFT | DT_TOP | DT_CALCRECT - ); - PhInflateRect(&bufferRect, 1, 0); - bufferRect.top += 1, bufferRect.bottom += 2; - if (bufferRect.bottom > DrawInfo->rc.bottom - 1) bufferRect.bottom = DrawInfo->rc.bottom - 1; - - for (INT i = 0; i < bufferRect.right - bufferRect.left - 1; i += 2) - SetPixel(DrawInfo->hdc, bufferRect.left + i + 1, bufferRect.bottom, PhThemeWindowHighlight2Color); - for (INT i = 0; i < bufferRect.bottom - bufferRect.top - 1; i += 2) - SetPixel(DrawInfo->hdc, bufferRect.right, bufferRect.bottom - i - 1, PhThemeWindowHighlight2Color); - for (INT i = 0; i < bufferRect.right - bufferRect.left - 1; i += 2) - SetPixel(DrawInfo->hdc, bufferRect.right - i - 1, bufferRect.top, PhThemeWindowHighlight2Color); - for (INT i = 0; i < bufferRect.bottom - bufferRect.top - 1; i += 2) - SetPixel(DrawInfo->hdc, bufferRect.left, bufferRect.top + i + 1, PhThemeWindowHighlight2Color); - } - - PhCloseThemeData(themeHandle); + DT_LEFT | DT_SINGLELINE | DT_VCENTER | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) + ); } else { - if (isChecked) - { - HFONT newFont = PhDuplicateFontWithNewHeight(PhApplicationFont, 16, dpiValue); - HFONT oldFont; - - oldFont = SelectFont(DrawInfo->hdc, newFont); - DrawText( - DrawInfo->hdc, - L"\u2611", - 1, - &DrawInfo->rc, - DT_LEFT | DT_SINGLELINE | DT_VCENTER - ); - SelectFont(DrawInfo->hdc, oldFont); - DeleteFont(newFont); - } - else - { - HFONT newFont = PhDuplicateFontWithNewHeight(PhApplicationFont, 22, dpiValue); - HFONT oldFont; - - oldFont = SelectFont(DrawInfo->hdc, newFont); - DrawText( - DrawInfo->hdc, - L"\u2610", - 1, - &DrawInfo->rc, - DT_LEFT | DT_SINGLELINE | DT_VCENTER - ); - SelectFont(DrawInfo->hdc, oldFont); - DeleteFont(newFont); - } - - bufferRect.left = 17; - bufferRect.right = DrawInfo->rc.right; + DrawText( + DrawInfo->hdc, + buttonText->Buffer, + (UINT)buttonText->Length / sizeof(WCHAR), + &bufferRect, + DT_LEFT | DT_TOP | DT_CALCRECT | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) + ); + + bufferRect.top = (DrawInfo->rc.bottom - DrawInfo->rc.top) / 2 - (bufferRect.bottom - bufferRect.top) / 2 - 1; + bufferRect.bottom = DrawInfo->rc.bottom, bufferRect.right = DrawInfo->rc.right; DrawText( DrawInfo->hdc, buttonText->Buffer, (UINT)buttonText->Length / sizeof(WCHAR), &bufferRect, - DT_LEFT | DT_VCENTER | DT_SINGLELINE | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) - ); + DT_LEFT | DT_TOP | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) + ); } - } - } - else - { - if (isSelected) - { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // //SetTextColor(DrawInfo->hdc, RGB(0, 0, 0xff)); - // SetDCBrushColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHT)); - // break; - //case 1: // Old colors - SetTextColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetDCBrushColor(DrawInfo->hdc, PhMakeColorBrighter(PhThemeWindowBackground2Color, 13)); // RGB(78, 78, 78) - FillRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); - } - else if (isHighlighted) - { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // //SetTextColor(DrawInfo->hdc, RGB(0, 0, 0xff)); - // SetDCBrushColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHT)); - // break; - //case 1: // Old colors - SetTextColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackground2Color); - FillRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); + + if (isKeyboardFocused) + { + DrawText( + DrawInfo->hdc, + buttonText->Buffer, + (UINT)buttonText->Length / sizeof(WCHAR), + &bufferRect, + DT_LEFT | DT_TOP | DT_CALCRECT + ); + PhInflateRect(&bufferRect, 1, 0); + bufferRect.top += 1, bufferRect.bottom += 2; + if (bufferRect.bottom > DrawInfo->rc.bottom - 1) bufferRect.bottom = DrawInfo->rc.bottom - 1; + + for (INT i = 0; i < bufferRect.right - bufferRect.left - 1; i += 2) + SetPixel(DrawInfo->hdc, bufferRect.left + i + 1, bufferRect.bottom, PhThemeWindowHighlight2Color); + for (INT i = 0; i < bufferRect.bottom - bufferRect.top - 1; i += 2) + SetPixel(DrawInfo->hdc, bufferRect.right, bufferRect.bottom - i - 1, PhThemeWindowHighlight2Color); + for (INT i = 0; i < bufferRect.right - bufferRect.left - 1; i += 2) + SetPixel(DrawInfo->hdc, bufferRect.right - i - 1, bufferRect.top, PhThemeWindowHighlight2Color); + for (INT i = 0; i < bufferRect.bottom - bufferRect.top - 1; i += 2) + SetPixel(DrawInfo->hdc, bufferRect.left, bufferRect.top + i + 1, PhThemeWindowHighlight2Color); + } + + PhCloseThemeData(themeHandle); } else { - SetTextColor(DrawInfo->hdc, !isDisabled ? PhThemeWindowTextColor : RGB(0x9B, 0x9B, 0x9B)); - //SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackgroundColor); // WindowForegroundColor - FillRect(DrawInfo->hdc, &DrawInfo->rc, PhThemeWindowBackgroundBrush); - } + if (isChecked) + { + HFONT newFont = PhDuplicateFontWithNewHeight(PhApplicationFont, 16, dpiValue); + HFONT oldFont; - SetBkMode(DrawInfo->hdc, TRANSPARENT); - SetDCBrushColor(DrawInfo->hdc, !isFocused ? PhThemeWindowBackground2Color : PhThemeWindowHighlightColor); - FrameRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); + oldFont = SelectFont(DrawInfo->hdc, newFont); + DrawText( + DrawInfo->hdc, + L"\u2611", + 1, + &DrawInfo->rc, + DT_LEFT | DT_SINGLELINE | DT_VCENTER + ); + SelectFont(DrawInfo->hdc, oldFont); + DeleteFont(newFont); + } + else + { + HFONT newFont = PhDuplicateFontWithNewHeight(PhApplicationFont, 22, dpiValue); + HFONT oldFont; - PhThemeDrawButtonIcon(DrawInfo, buttonIcon, &bufferRect, dpiValue); + oldFont = SelectFont(DrawInfo->hdc, newFont); + DrawText( + DrawInfo->hdc, + L"\u2610", + 1, + &DrawInfo->rc, + DT_LEFT | DT_SINGLELINE | DT_VCENTER + ); + SelectFont(DrawInfo->hdc, oldFont); + DeleteFont(newFont); + } + + bufferRect.left = 17; + bufferRect.right = DrawInfo->rc.right; - if ((buttonStyle & BS_ICON) != BS_ICON) - { DrawText( DrawInfo->hdc, buttonText->Buffer, (UINT)buttonText->Length / sizeof(WCHAR), &bufferRect, - DT_CENTER | DT_SINGLELINE | DT_VCENTER | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) - ); + DT_LEFT | DT_VCENTER | DT_SINGLELINE | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) + ); } } - PhDereferenceObject(buttonText); } + else + { + if (isSelected) + { + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // //SetTextColor(DrawInfo->hdc, RGB(0, 0, 0xff)); + // SetDCBrushColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHT)); + // break; + //case 1: // Old colors + SetTextColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetDCBrushColor(DrawInfo->hdc, PhMakeColorBrighter(PhThemeWindowBackground2Color, 13)); // RGB(78, 78, 78) + FillRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); + } + else if (isHighlighted) + { + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // //SetTextColor(DrawInfo->hdc, RGB(0, 0, 0xff)); + // SetDCBrushColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHT)); + // break; + //case 1: // Old colors + SetTextColor(DrawInfo->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackground2Color); + FillRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); + } + else + { + SetTextColor(DrawInfo->hdc, !isDisabled ? PhThemeWindowTextColor : RGB(0x9B, 0x9B, 0x9B)); + //SetDCBrushColor(DrawInfo->hdc, PhThemeWindowBackgroundColor); // WindowForegroundColor + FillRect(DrawInfo->hdc, &DrawInfo->rc, PhThemeWindowBackgroundBrush); + } + + SetBkMode(DrawInfo->hdc, TRANSPARENT); + SetDCBrushColor(DrawInfo->hdc, !isFocused ? PhThemeWindowBackground2Color : PhThemeWindowHighlightColor); + FrameRect(DrawInfo->hdc, &DrawInfo->rc, PhGetStockBrush(DC_BRUSH)); + + PhThemeDrawButtonIcon(DrawInfo, buttonIcon, &bufferRect, dpiValue); + + if ((buttonStyle & BS_ICON) != BS_ICON) + { + DrawText( + DrawInfo->hdc, + buttonText->Buffer, + (UINT)buttonText->Length / sizeof(WCHAR), + &bufferRect, + DT_CENTER | DT_SINGLELINE | DT_VCENTER | (!isKeyboardFocused ? DT_HIDEPREFIX : 0) + ); + } + } + PhDereferenceObject(buttonText); + } - return CDRF_SKIPDEFAULT; + return CDRF_SKIPDEFAULT; } return CDRF_DODEFAULT; @@ -1840,7 +1859,7 @@ LRESULT CALLBACK PhThemeWindowDrawButton( LRESULT CALLBACK PhThemeWindowDrawRebar( _In_ LPNMCUSTOMDRAW DrawInfo - ) +) { // temp chevron workaround until location/state supported. if (DrawInfo->dwDrawStage != CDDS_PREPAINT) @@ -1849,19 +1868,19 @@ LRESULT CALLBACK PhThemeWindowDrawRebar( switch (DrawInfo->dwDrawStage) { case CDDS_PREPAINT: - { - //REBARBANDINFO bandinfo = { sizeof(REBARBANDINFO), RBBIM_CHILD | RBBIM_STYLE | RBBIM_CHEVRONLOCATION | RBBIM_CHEVRONSTATE }; - //BOOL havebandinfo = (BOOL)SendMessage(DrawInfo->hdr.hwndFrom, RB_GETBANDINFO, DrawInfo->dwItemSpec, (LPARAM)&bandinfo); + { + //REBARBANDINFO bandinfo = { sizeof(REBARBANDINFO), RBBIM_CHILD | RBBIM_STYLE | RBBIM_CHEVRONLOCATION | RBBIM_CHEVRONSTATE }; + //BOOL havebandinfo = (BOOL)SendMessage(DrawInfo->hdr.hwndFrom, RB_GETBANDINFO, DrawInfo->dwItemSpec, (LPARAM)&bandinfo); - SetTextColor(DrawInfo->hdc, PhThemeWindowTextColor); - FillRect(DrawInfo->hdc, &DrawInfo->rc, PhThemeWindowBackgroundBrush); - } - return CDRF_NOTIFYITEMDRAW; + SetTextColor(DrawInfo->hdc, PhThemeWindowTextColor); + FillRect(DrawInfo->hdc, &DrawInfo->rc, PhThemeWindowBackgroundBrush); + } + return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: - { + { - } - return CDRF_SKIPDEFAULT; + } + return CDRF_SKIPDEFAULT; } return CDRF_DODEFAULT; @@ -1869,231 +1888,231 @@ LRESULT CALLBACK PhThemeWindowDrawRebar( LRESULT CALLBACK PhThemeWindowDrawToolbar( _In_ LPNMTBCUSTOMDRAW DrawInfo - ) +) { switch (DrawInfo->nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT; case CDDS_ITEMPREPAINT: + { + TBBUTTONINFO buttonInfo = { - TBBUTTONINFO buttonInfo = - { - sizeof(TBBUTTONINFO), - TBIF_STYLE | TBIF_COMMAND | TBIF_STATE | TBIF_IMAGE - }; + sizeof(TBBUTTONINFO), + TBIF_STYLE | TBIF_COMMAND | TBIF_STATE | TBIF_IMAGE + }; - SetBkMode(DrawInfo->nmcd.hdc, TRANSPARENT); + SetBkMode(DrawInfo->nmcd.hdc, TRANSPARENT); - LONG dpiValue; - INT bitmapWidth = 0; - INT bitmapHeight = 0; - - ULONG currentIndex = (ULONG)SendMessage( - DrawInfo->nmcd.hdr.hwndFrom, - TB_COMMANDTOINDEX, - DrawInfo->nmcd.dwItemSpec, - 0 - ); - BOOLEAN isHighlighted = SendMessage( - DrawInfo->nmcd.hdr.hwndFrom, - TB_GETHOTITEM, - 0, - 0 - ) == currentIndex; - BOOLEAN isMouseDown = SendMessage( - DrawInfo->nmcd.hdr.hwndFrom, - TB_ISBUTTONPRESSED, - DrawInfo->nmcd.dwItemSpec, - 0 - ) == 0; - BOOLEAN isEnabled = SendMessage( - DrawInfo->nmcd.hdr.hwndFrom, - TB_ISBUTTONENABLED, - DrawInfo->nmcd.dwItemSpec, - 0 - ) != 0; + LONG dpiValue; + INT bitmapWidth = 0; + INT bitmapHeight = 0; - if (SendMessage( - DrawInfo->nmcd.hdr.hwndFrom, - TB_GETBUTTONINFO, - (ULONG)DrawInfo->nmcd.dwItemSpec, - (LPARAM)&buttonInfo - ) == INT_ERROR) - { - break; - } + ULONG currentIndex = (ULONG)SendMessage( + DrawInfo->nmcd.hdr.hwndFrom, + TB_COMMANDTOINDEX, + DrawInfo->nmcd.dwItemSpec, + 0 + ); + BOOLEAN isHighlighted = SendMessage( + DrawInfo->nmcd.hdr.hwndFrom, + TB_GETHOTITEM, + 0, + 0 + ) == currentIndex; + BOOLEAN isMouseDown = SendMessage( + DrawInfo->nmcd.hdr.hwndFrom, + TB_ISBUTTONPRESSED, + DrawInfo->nmcd.dwItemSpec, + 0 + ) == 0; + BOOLEAN isEnabled = SendMessage( + DrawInfo->nmcd.hdr.hwndFrom, + TB_ISBUTTONENABLED, + DrawInfo->nmcd.dwItemSpec, + 0 + ) != 0; + + if (SendMessage( + DrawInfo->nmcd.hdr.hwndFrom, + TB_GETBUTTONINFO, + (ULONG)DrawInfo->nmcd.dwItemSpec, + (LPARAM)&buttonInfo + ) == INT_ERROR) + { + break; + } + + BOOLEAN isDropDown = !!(buttonInfo.fsStyle & BTNS_WHOLEDROPDOWN); + + //if (isMouseDown) + //{ + // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); + // SetDCBrushColor(DrawInfo->nmcd.hdc, RGB(0xff, 0xff, 0xff)); + // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); + //} - BOOLEAN isDropDown = !!(buttonInfo.fsStyle & BTNS_WHOLEDROPDOWN); + if (isHighlighted) + { + //INT stateId; + //// Themed background + //if (node->Selected) + //{ + // if (i == Context->HotNodeIndex) + // stateId = TREIS_HOTSELECTED; + // else if (!Context->HasFocus) + // stateId = TREIS_SELECTEDNOTFOCUS; + // else + // stateId = TREIS_SELECTED; + //} + //else + //{ + // if (i == Context->HotNodeIndex) + // stateId = TREIS_HOT; + // else + // stateId = INT_MAX; + //} + //// Themed background + //if (stateId != INT_MAX) + //if (!Context->FixedColumnVisible) + //{ + // rowRect.left = Context->NormalLeft - hScrollPosition; + //} + //switch (PhpThemeColorMode) + //{ + //case 0: // New colors + // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); + // SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackgroundColor); + // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); + // break; + //case 1: // Old colors + // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); + // SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowHighlightColor); + // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); + // break; + //} - //if (isMouseDown) + SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); + SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowHighlightColor); + FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); + } + else + { + //switch (PhpThemeColorMode) //{ + //case 0: // New colors + // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); // RGB(0x0, 0x0, 0x0)); + // SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackgroundColor); // GetSysColor(COLOR_3DFACE));// RGB(0xff, 0xff, 0xff)); + // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); + // break; + //case 1: // Old colors // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); - // SetDCBrushColor(DrawInfo->nmcd.hdc, RGB(0xff, 0xff, 0xff)); + // SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackgroundColor); //PhThemeWindowForegroundColor); // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); + // break; //} - if (isHighlighted) + BOOLEAN isPressed = buttonInfo.fsState & TBSTATE_PRESSED; + SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); // RGB(0x0, 0x0, 0x0)); + //SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackgroundColor); // GetSysColor(COLOR_3DFACE));// RGB(0xff, 0xff, 0xff)); + if (!isPressed) + FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhThemeWindowBackgroundBrush); + else { - //INT stateId; - //// Themed background - //if (node->Selected) - //{ - // if (i == Context->HotNodeIndex) - // stateId = TREIS_HOTSELECTED; - // else if (!Context->HasFocus) - // stateId = TREIS_SELECTEDNOTFOCUS; - // else - // stateId = TREIS_SELECTED; - //} - //else - //{ - // if (i == Context->HotNodeIndex) - // stateId = TREIS_HOT; - // else - // stateId = INT_MAX; - //} - //// Themed background - //if (stateId != INT_MAX) - //if (!Context->FixedColumnVisible) - //{ - // rowRect.left = Context->NormalLeft - hScrollPosition; - //} - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); - // SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackgroundColor); - // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); - // break; - //case 1: // Old colors - // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); - // SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowHighlightColor); - // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); - // break; - //} - - SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); - SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowHighlightColor); + SetDCBrushColor(DrawInfo->nmcd.hdc, PhMakeColorBrighter(PhThemeWindowBackground2Color, 31)); // RGB(96, 96, 96) FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); } - else - { - //switch (PhpThemeColorMode) - //{ - //case 0: // New colors - // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); // RGB(0x0, 0x0, 0x0)); - // SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackgroundColor); // GetSysColor(COLOR_3DFACE));// RGB(0xff, 0xff, 0xff)); - // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); - // break; - //case 1: // Old colors - // SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); - // SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackgroundColor); //PhThemeWindowForegroundColor); - // FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); - // break; - //} + } - BOOLEAN isPressed = buttonInfo.fsState & TBSTATE_PRESSED; - SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); // RGB(0x0, 0x0, 0x0)); - //SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackgroundColor); // GetSysColor(COLOR_3DFACE));// RGB(0xff, 0xff, 0xff)); - if (!isPressed) - FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhThemeWindowBackgroundBrush); - else - { - SetDCBrushColor(DrawInfo->nmcd.hdc, PhMakeColorBrighter(PhThemeWindowBackground2Color, 31)); // RGB(96, 96, 96) - FillRect(DrawInfo->nmcd.hdc, &DrawInfo->nmcd.rc, PhGetStockBrush(DC_BRUSH)); - } - } + dpiValue = PhGetWindowDpi(DrawInfo->nmcd.hdr.hwndFrom); - dpiValue = PhGetWindowDpi(DrawInfo->nmcd.hdr.hwndFrom); + SelectFont(DrawInfo->nmcd.hdc, GetWindowFont(DrawInfo->nmcd.hdr.hwndFrom)); - SelectFont(DrawInfo->nmcd.hdc, GetWindowFont(DrawInfo->nmcd.hdr.hwndFrom)); + if (buttonInfo.iImage != I_IMAGECALLBACK) + { + HIMAGELIST toolbarImageList; - if (buttonInfo.iImage != I_IMAGECALLBACK) + if (toolbarImageList = (HIMAGELIST)SendMessage( + DrawInfo->nmcd.hdr.hwndFrom, + TB_GETIMAGELIST, + 0, + 0 + )) { - HIMAGELIST toolbarImageList; + LONG x; + LONG y; - if (toolbarImageList = (HIMAGELIST)SendMessage( - DrawInfo->nmcd.hdr.hwndFrom, - TB_GETIMAGELIST, - 0, - 0 - )) - { - LONG x; - LONG y; - - PhImageListGetIconSize(toolbarImageList, &bitmapWidth, &bitmapHeight); - - if (buttonInfo.fsStyle & BTNS_SHOWTEXT) - { - DrawInfo->nmcd.rc.left += PhGetSystemMetrics(SM_CXEDGE, dpiValue); // PhGetDpi(5, dpiValue); - x = DrawInfo->nmcd.rc.left;// + ((DrawInfo->nmcd.rc.right - DrawInfo->nmcd.rc.left) - PhSmallIconSize.X) / 2; - y = DrawInfo->nmcd.rc.top + ((DrawInfo->nmcd.rc.bottom - DrawInfo->nmcd.rc.top) - bitmapHeight) / 2; - } - else - { - x = DrawInfo->nmcd.rc.left + ((DrawInfo->nmcd.rc.right - DrawInfo->nmcd.rc.left) - bitmapWidth) / 2 - (isDropDown * 4); - y = DrawInfo->nmcd.rc.top + ((DrawInfo->nmcd.rc.bottom - DrawInfo->nmcd.rc.top) - bitmapHeight) / 2; - } + PhImageListGetIconSize(toolbarImageList, &bitmapWidth, &bitmapHeight); - PhImageListDrawIcon( - toolbarImageList, - buttonInfo.iImage, - DrawInfo->nmcd.hdc, - x, - y, - ILD_NORMAL, - !isEnabled - ); + if (buttonInfo.fsStyle & BTNS_SHOWTEXT) + { + DrawInfo->nmcd.rc.left += PhGetSystemMetrics(SM_CXEDGE, dpiValue); // PhGetDpi(5, dpiValue); + x = DrawInfo->nmcd.rc.left;// + ((DrawInfo->nmcd.rc.right - DrawInfo->nmcd.rc.left) - PhSmallIconSize.X) / 2; + y = DrawInfo->nmcd.rc.top + ((DrawInfo->nmcd.rc.bottom - DrawInfo->nmcd.rc.top) - bitmapHeight) / 2; + } + else + { + x = DrawInfo->nmcd.rc.left + ((DrawInfo->nmcd.rc.right - DrawInfo->nmcd.rc.left) - bitmapWidth) / 2 - (isDropDown * 4); + y = DrawInfo->nmcd.rc.top + ((DrawInfo->nmcd.rc.bottom - DrawInfo->nmcd.rc.top) - bitmapHeight) / 2; + } - if (isDropDown) - { - HDC hdc = DrawInfo->nmcd.hdc; - LPRECT rc = &DrawInfo->nmcd.rc; - int triangleLeft = rc->right - 11, triangleTop = (rc->bottom - rc->top) / 2 - 2; - POINT vertices[] = { {triangleLeft, triangleTop}, {triangleLeft + 6, triangleTop}, {triangleLeft + 3, triangleTop + 3} }; - SetDCPenColor(hdc, RGB(0xDE, 0xDE, 0xDE)); - SetDCBrushColor(hdc, RGB(0xDE, 0xDE, 0xDE)); - SelectPen(hdc, PhGetStockPen(DC_PEN)); - SelectBrush(hdc, PhGetStockBrush(DC_BRUSH)); - Polygon(hdc, vertices, _countof(vertices)); - } + PhImageListDrawIcon( + toolbarImageList, + buttonInfo.iImage, + DrawInfo->nmcd.hdc, + x, + y, + ILD_NORMAL, + !isEnabled + ); - //return CDRF_SKIPDEFAULT | CDRF_NOTIFYPOSTPAINT; + if (isDropDown) + { + HDC hdc = DrawInfo->nmcd.hdc; + LPRECT rc = &DrawInfo->nmcd.rc; + int triangleLeft = rc->right - 11, triangleTop = (rc->bottom - rc->top) / 2 - 2; + POINT vertices[] = { {triangleLeft, triangleTop}, {triangleLeft + 6, triangleTop}, {triangleLeft + 3, triangleTop + 3} }; + SetDCPenColor(hdc, RGB(0xDE, 0xDE, 0xDE)); + SetDCBrushColor(hdc, RGB(0xDE, 0xDE, 0xDE)); + SelectPen(hdc, PhGetStockPen(DC_PEN)); + SelectBrush(hdc, PhGetStockBrush(DC_BRUSH)); + Polygon(hdc, vertices, _countof(vertices)); } + + //return CDRF_SKIPDEFAULT | CDRF_NOTIFYPOSTPAINT; } - else - { - return CDRF_DODEFAULT; // Required for I_IMAGECALLBACK (dmex) - } + } + else + { + return CDRF_DODEFAULT; // Required for I_IMAGECALLBACK (dmex) + } - if (buttonInfo.fsStyle & BTNS_SHOWTEXT) - { - RECT textRect = DrawInfo->nmcd.rc; - WCHAR buttonText[MAX_PATH] = L""; - - SendMessage( - DrawInfo->nmcd.hdr.hwndFrom, - TB_GETBUTTONTEXT, - (ULONG)DrawInfo->nmcd.dwItemSpec, - (LPARAM)buttonText - ); + if (buttonInfo.fsStyle & BTNS_SHOWTEXT) + { + RECT textRect = DrawInfo->nmcd.rc; + WCHAR buttonText[MAX_PATH] = L""; - textRect.left += bitmapWidth - (isDropDown * 12); // PhGetDpi(10, dpiValue); - DrawText( - DrawInfo->nmcd.hdc, - buttonText, - (UINT)PhCountStringZ(buttonText), - &textRect, - DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX - ); - } + SendMessage( + DrawInfo->nmcd.hdr.hwndFrom, + TB_GETBUTTONTEXT, + (ULONG)DrawInfo->nmcd.dwItemSpec, + (LPARAM)buttonText + ); - //DrawInfo->clrText = RGB(0x0, 0xff, 0); - //return TBCDRF_USECDCOLORS | CDRF_NEWFONT; + textRect.left += bitmapWidth - (isDropDown * 12); // PhGetDpi(10, dpiValue); + DrawText( + DrawInfo->nmcd.hdc, + buttonText, + (UINT)PhCountStringZ(buttonText), + &textRect, + DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX + ); } - return CDRF_SKIPDEFAULT; + + //DrawInfo->clrText = RGB(0x0, 0xff, 0); + //return TBCDRF_USECDCOLORS | CDRF_NEWFONT; + } + return CDRF_SKIPDEFAULT; } return CDRF_DODEFAULT; @@ -2101,67 +2120,67 @@ LRESULT CALLBACK PhThemeWindowDrawToolbar( LRESULT CALLBACK PhpThemeWindowDrawListViewGroup( _In_ LPNMLVCUSTOMDRAW DrawInfo - ) +) { switch (DrawInfo->nmcd.dwDrawStage) { case CDDS_PREPAINT: + { + LONG dpiValue = PhGetWindowDpi(DrawInfo->nmcd.hdr.hwndFrom); + HFONT fontHandle = NULL; + LVGROUP groupInfo; + { - LONG dpiValue = PhGetWindowDpi(DrawInfo->nmcd.hdr.hwndFrom); - HFONT fontHandle = NULL; - LVGROUP groupInfo; + NONCLIENTMETRICS metrics = { sizeof(NONCLIENTMETRICS) }; + if (PhGetSystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, dpiValue)) { - NONCLIENTMETRICS metrics = { sizeof(NONCLIENTMETRICS) }; - - if (PhGetSystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, dpiValue)) - { - metrics.lfMessageFont.lfHeight = PhGetDpi(-11, dpiValue); - metrics.lfMessageFont.lfWeight = FW_BOLD; + metrics.lfMessageFont.lfHeight = PhGetDpi(-11, dpiValue); + metrics.lfMessageFont.lfWeight = FW_BOLD; - fontHandle = CreateFontIndirect(&metrics.lfMessageFont); - } + fontHandle = CreateFontIndirect(&metrics.lfMessageFont); } + } - SetBkMode(DrawInfo->nmcd.hdc, TRANSPARENT); - //SelectFont(DrawInfo->nmcd.hdc, GetWindowFont(DrawInfo->nmcd.hdr.hwndFrom)); - SelectFont(DrawInfo->nmcd.hdc, fontHandle); + SetBkMode(DrawInfo->nmcd.hdc, TRANSPARENT); + //SelectFont(DrawInfo->nmcd.hdc, GetWindowFont(DrawInfo->nmcd.hdr.hwndFrom)); + SelectFont(DrawInfo->nmcd.hdc, fontHandle); - memset(&groupInfo, 0, sizeof(LVGROUP)); - groupInfo.cbSize = sizeof(LVGROUP); - groupInfo.mask = LVGF_HEADER; + memset(&groupInfo, 0, sizeof(LVGROUP)); + groupInfo.cbSize = sizeof(LVGROUP); + groupInfo.mask = LVGF_HEADER; - if (ListView_GetGroupInfo(DrawInfo->nmcd.hdr.hwndFrom, (ULONG)DrawInfo->nmcd.dwItemSpec, &groupInfo) != INT_ERROR) - { - SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); - SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackground2Color); + if (ListView_GetGroupInfo(DrawInfo->nmcd.hdr.hwndFrom, (ULONG)DrawInfo->nmcd.dwItemSpec, &groupInfo) != INT_ERROR) + { + SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor); + SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackground2Color); - DrawInfo->rcText.top += PhGetDpi(2, dpiValue); - DrawInfo->rcText.bottom -= PhGetDpi(2, dpiValue); - FillRect(DrawInfo->nmcd.hdc, &DrawInfo->rcText, PhGetStockBrush(DC_BRUSH)); - DrawInfo->rcText.top -= PhGetDpi(2, dpiValue); - DrawInfo->rcText.bottom += PhGetDpi(2, dpiValue); + DrawInfo->rcText.top += PhGetDpi(2, dpiValue); + DrawInfo->rcText.bottom -= PhGetDpi(2, dpiValue); + FillRect(DrawInfo->nmcd.hdc, &DrawInfo->rcText, PhGetStockBrush(DC_BRUSH)); + DrawInfo->rcText.top -= PhGetDpi(2, dpiValue); + DrawInfo->rcText.bottom += PhGetDpi(2, dpiValue); - if (groupInfo.pszHeader) - { - DrawInfo->rcText.left += PhGetDpi(10, dpiValue); - DrawText( - DrawInfo->nmcd.hdc, - groupInfo.pszHeader, - (UINT)PhCountStringZ(groupInfo.pszHeader), - &DrawInfo->rcText, - DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX - ); - DrawInfo->rcText.left -= PhGetDpi(10, dpiValue); - } - } - - if (fontHandle) + if (groupInfo.pszHeader) { - DeleteFont(fontHandle); + DrawInfo->rcText.left += PhGetDpi(10, dpiValue); + DrawText( + DrawInfo->nmcd.hdc, + groupInfo.pszHeader, + (UINT)PhCountStringZ(groupInfo.pszHeader), + &DrawInfo->rcText, + DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX + ); + DrawInfo->rcText.left -= PhGetDpi(10, dpiValue); } } - return CDRF_SKIPDEFAULT; + + if (fontHandle) + { + DeleteFont(fontHandle); + } + } + return CDRF_SKIPDEFAULT; } return CDRF_DODEFAULT; @@ -2172,7 +2191,7 @@ LRESULT CALLBACK PhpThemeWindowSubclassProc( _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam - ) +) { WNDPROC oldWndProc; @@ -2182,83 +2201,82 @@ LRESULT CALLBACK PhpThemeWindowSubclassProc( switch (uMsg) { case WM_NCDESTROY: - { - PhRemoveWindowContext(hWnd, LONG_MAX); - SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)oldWndProc); - } - break; + { + PhRemoveWindowContext(hWnd, LONG_MAX); + PhSetWindowProcedure(hWnd, oldWndProc); + } + break; case WM_NOTIFY: - { - LPNMHDR data = (LPNMHDR)lParam; + { + LPNMHDR data = (LPNMHDR)lParam; - switch (data->code) - { - case NM_CUSTOMDRAW: - { - LPNMCUSTOMDRAW customDraw = (LPNMCUSTOMDRAW)lParam; - WCHAR className[MAX_PATH]; + switch (data->code) + { + case NM_CUSTOMDRAW: + { + LPNMCUSTOMDRAW customDraw = (LPNMCUSTOMDRAW)lParam; + WCHAR className[MAX_PATH]; - if (!GetClassName(customDraw->hdr.hwndFrom, className, RTL_NUMBER_OF(className))) - className[0] = UNICODE_NULL; + GETCLASSNAME_OR_NULL(customDraw->hdr.hwndFrom, className); - if (PhEqualStringZ(className, WC_BUTTON, FALSE)) - { - return PhThemeWindowDrawButton(customDraw); - } - else if (PhEqualStringZ(className, REBARCLASSNAME, FALSE)) - { - return PhThemeWindowDrawRebar(customDraw); - } - else if (PhEqualStringZ(className, TOOLBARCLASSNAME, FALSE)) - { - return PhThemeWindowDrawToolbar((LPNMTBCUSTOMDRAW)customDraw); - } - else if (PhEqualStringZ(className, WC_LISTVIEW, FALSE)) - { - LPNMLVCUSTOMDRAW listViewCustomDraw = (LPNMLVCUSTOMDRAW)customDraw; + if (PhEqualStringZ(className, WC_BUTTON, FALSE)) + { + return PhThemeWindowDrawButton(customDraw); + } + else if (PhEqualStringZ(className, REBARCLASSNAME, FALSE)) + { + return PhThemeWindowDrawRebar(customDraw); + } + else if (PhEqualStringZ(className, TOOLBARCLASSNAME, FALSE)) + { + return PhThemeWindowDrawToolbar((LPNMTBCUSTOMDRAW)customDraw); + } + else if (PhEqualStringZ(className, WC_LISTVIEW, FALSE)) + { + LPNMLVCUSTOMDRAW listViewCustomDraw = (LPNMLVCUSTOMDRAW)customDraw; - if (listViewCustomDraw->dwItemType == LVCDI_GROUP) - { - return PhpThemeWindowDrawListViewGroup(listViewCustomDraw); - } - } - else - { - //dprintf("NM_CUSTOMDRAW: %S\r\n", className); - } + if (listViewCustomDraw->dwItemType == LVCDI_GROUP) + { + return PhpThemeWindowDrawListViewGroup(listViewCustomDraw); } } + else + { + //dprintf("NM_CUSTOMDRAW: %S\r\n", className); + } } - break; + } + } + break; case WM_CTLCOLOREDIT: - { - HDC hdc = (HDC)wParam; + { + HDC hdc = (HDC)wParam; - //Fix typing in multiline edit (Dart Vanya) - if (PhGetWindowStyle((HWND)lParam) & ES_MULTILINE) - SetBkColor(hdc, PhThemeWindowBackground2Color); - else - SetBkMode(hdc, TRANSPARENT); - SetTextColor(hdc, PhThemeWindowTextColor); - SetDCBrushColor(hdc, PhThemeWindowBackground2Color); - return (INT_PTR)PhGetStockBrush(DC_BRUSH); - } - break; + //Fix typing in multiline edit (Dart Vanya) + if (PhGetWindowStyle((HWND)lParam) & ES_MULTILINE) + SetBkColor(hdc, PhThemeWindowBackground2Color); + else + SetBkMode(hdc, TRANSPARENT); + SetTextColor(hdc, PhThemeWindowTextColor); + SetDCBrushColor(hdc, PhThemeWindowBackground2Color); + return (INT_PTR)PhGetStockBrush(DC_BRUSH); + } + break; case WM_CTLCOLORBTN: case WM_CTLCOLORDLG: case WM_CTLCOLORSTATIC: case WM_CTLCOLORLISTBOX: - { - HDC hdc = (HDC)wParam; + { + HDC hdc = (HDC)wParam; - if (uMsg == WM_CTLCOLORBTN) // for correct drawing of system KEYBOARDCUES - SetBkColor(hdc, PhThemeWindowBackground2Color); - else - SetBkMode(hdc, TRANSPARENT); - SetTextColor(hdc, PhThemeWindowTextColor); - return (INT_PTR)PhThemeWindowBackgroundBrush; - } - break; + if (uMsg == WM_CTLCOLORBTN) // for correct drawing of system KEYBOARDCUES + SetBkColor(hdc, PhThemeWindowBackground2Color); + else + SetBkMode(hdc, TRANSPARENT); + SetTextColor(hdc, PhThemeWindowTextColor); + return (INT_PTR)PhThemeWindowBackgroundBrush; + } + break; case WM_MEASUREITEM: if (PhThemeWindowMeasureItem(hWnd, (LPMEASUREITEMSTRUCT)lParam)) @@ -2270,14 +2288,14 @@ LRESULT CALLBACK PhpThemeWindowSubclassProc( break; case WM_NCPAINT: case WM_NCACTIVATE: - { - LRESULT result = CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); + { + LRESULT result = CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); - PhWindowThemeMainMenuBorder(hWnd); + PhWindowThemeMainMenuBorder(hWnd); - return result; - } - break; + return result; + } + break; } return CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam); @@ -2288,7 +2306,7 @@ VOID ThemeWindowRenderGroupBoxControl( _In_ HDC bufferDc, _In_ PRECT clientRect, _In_ WNDPROC WindowProcedure - ) +) { ULONG returnLength; WCHAR text[0x80]; @@ -2311,7 +2329,7 @@ VOID ThemeWindowRenderGroupBoxControl( text, returnLength, &nameSize - ); + ); bufferRect.left = 0; bufferRect.top = 0; @@ -2329,7 +2347,7 @@ VOID ThemeWindowRenderGroupBoxControl( returnLength, &bufferRect, DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE - ); + ); bufferRect.left -= PhGetDpi(10, dpiValue); } } @@ -2339,7 +2357,7 @@ LRESULT CALLBACK PhpThemeWindowGroupBoxSubclassProc( _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam - ) +) { WNDPROC oldWndProc; @@ -2349,31 +2367,31 @@ LRESULT CALLBACK PhpThemeWindowGroupBoxSubclassProc( switch (uMsg) { case WM_NCDESTROY: - { - SetWindowLongPtr(WindowHandle, GWLP_WNDPROC, (LONG_PTR)oldWndProc); - PhRemoveWindowContext(WindowHandle, LONG_MAX); - } - break; + { + PhRemoveWindowContext(WindowHandle, LONG_MAX); + PhSetWindowProcedure(WindowHandle, oldWndProc); + } + break; case WM_ERASEBKGND: - { - HDC hdc = (HDC)wParam; - RECT clientRect; + { + HDC hdc = (HDC)wParam; + RECT clientRect; - GetClientRect(WindowHandle, &clientRect); + GetClientRect(WindowHandle, &clientRect); - ThemeWindowRenderGroupBoxControl(WindowHandle, hdc, &clientRect, oldWndProc); - } - return TRUE; + ThemeWindowRenderGroupBoxControl(WindowHandle, hdc, &clientRect, oldWndProc); + } + return TRUE; case WM_ENABLE: if (!wParam) // fix drawing when window visible and switches to disabled return 0; case WM_PAINT: - { - PAINTSTRUCT ps; - BeginPaint(WindowHandle, &ps); - EndPaint(WindowHandle, &ps); - } - return 0; + { + PAINTSTRUCT ps; + BeginPaint(WindowHandle, &ps); + EndPaint(WindowHandle, &ps); + } + return 0; } return CallWindowProc(oldWndProc, WindowHandle, uMsg, wParam, lParam); @@ -2385,7 +2403,7 @@ VOID ThemeWindowRenderTabControl( _In_ HDC bufferDc, _In_ PRECT clientRect, _In_ WNDPROC WindowProcedure - ) +) { //RECT windowRect; @@ -2555,7 +2573,7 @@ VOID ThemeWindowRenderTabControl( (UINT)PhCountStringZ(tabItem.pszText), &itemRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX - ); + ); } } } @@ -2580,7 +2598,7 @@ VOID ThemeWindowRenderTabControl( (UINT)PhCountStringZ(tabItem.pszText), &itemRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX - ); + ); } //if (itemHighlighted != INT_ERROR) @@ -2607,7 +2625,7 @@ LRESULT CALLBACK PhpThemeWindowTabControlWndSubclassProc( _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam - ) +) { PPHP_THEME_WINDOW_TAB_CONTEXT context; WNDPROC oldWndProc; @@ -2620,140 +2638,140 @@ LRESULT CALLBACK PhpThemeWindowTabControlWndSubclassProc( switch (uMsg) { case WM_NCDESTROY: - { - PhRemoveWindowContext(WindowHandle, LONG_MAX); - SetWindowLongPtr(WindowHandle, GWLP_WNDPROC, (LONG_PTR)oldWndProc); + { + PhRemoveWindowContext(WindowHandle, LONG_MAX); + PhSetWindowProcedure(WindowHandle, oldWndProc); - PhFree(context); - } - break; + PhFree(context); + } + break; case WM_ERASEBKGND: return TRUE; case WM_MOUSEMOVE: - { - //INT count; - //INT i; - // - //count = TabCtrl_GetItemCount(WindowHandle); - // - //for (i = 0; i < count; i++) - //{ - // RECT rect = { 0, 0, 0, 0 }; - // TCITEM entry = - // { - // TCIF_STATE, - // 0, - // TCIS_HIGHLIGHTED - // }; - // - // TabCtrl_GetItemRect(WindowHandle, i, &rect); - // entry.dwState = PhPtInRect(&rect, context->CursorPos) ? TCIS_HIGHLIGHTED : 0; - // TabCtrl_SetItem(WindowHandle, i, &entry); - //} + { + //INT count; + //INT i; + // + //count = TabCtrl_GetItemCount(WindowHandle); + // + //for (i = 0; i < count; i++) + //{ + // RECT rect = { 0, 0, 0, 0 }; + // TCITEM entry = + // { + // TCIF_STATE, + // 0, + // TCIS_HIGHLIGHTED + // }; + // + // TabCtrl_GetItemRect(WindowHandle, i, &rect); + // entry.dwState = PhPtInRect(&rect, context->CursorPos) ? TCIS_HIGHLIGHTED : 0; + // TabCtrl_SetItem(WindowHandle, i, &entry); + //} - if (!context->MouseActive) + if (!context->MouseActive) + { + TRACKMOUSEEVENT trackEvent = { - TRACKMOUSEEVENT trackEvent = - { - sizeof(TRACKMOUSEEVENT), - TME_LEAVE, - WindowHandle, - 0 - }; - - TrackMouseEvent(&trackEvent); - context->MouseActive = TRUE; - } - - context->CursorPos.x = GET_X_LPARAM(lParam); - context->CursorPos.y = GET_Y_LPARAM(lParam); + sizeof(TRACKMOUSEEVENT), + TME_LEAVE, + WindowHandle, + 0 + }; - InvalidateRect(WindowHandle, NULL, FALSE); + TrackMouseEvent(&trackEvent); + context->MouseActive = TRUE; } - break; + + context->CursorPos.x = GET_X_LPARAM(lParam); + context->CursorPos.y = GET_Y_LPARAM(lParam); + + InvalidateRect(WindowHandle, NULL, FALSE); + } + break; case WM_MOUSELEAVE: - { - //INT count; - //INT i; - // - //count = TabCtrl_GetItemCount(WindowHandle); - // - //for (i = 0; i < count; i++) - //{ - // TCITEM entry = - // { - // TCIF_STATE, - // 0, - // TCIS_HIGHLIGHTED - // }; - // - // TabCtrl_SetItem(WindowHandle, i, &entry); - //} + { + //INT count; + //INT i; + // + //count = TabCtrl_GetItemCount(WindowHandle); + // + //for (i = 0; i < count; i++) + //{ + // TCITEM entry = + // { + // TCIF_STATE, + // 0, + // TCIS_HIGHLIGHTED + // }; + // + // TabCtrl_SetItem(WindowHandle, i, &entry); + //} - context->CursorPos.x = LONG_MIN; - context->CursorPos.y = LONG_MIN; + context->CursorPos.x = LONG_MIN; + context->CursorPos.y = LONG_MIN; - context->MouseActive = FALSE; - InvalidateRect(WindowHandle, NULL, FALSE); - } - break; + context->MouseActive = FALSE; + InvalidateRect(WindowHandle, NULL, FALSE); + } + break; case WM_PAINT: + { + //PAINTSTRUCT ps; + //HDC BufferedHDC; + //HPAINTBUFFER BufferedPaint; + // + //if (!BeginPaint(WindowHandle, &ps)) + // break; + // + //DEBUG_BEGINPAINT_RECT(WindowHandle, ps.rcPaint); + // + //{ + // RECT clientRect; + // GetClientRect(WindowHandle, &clientRect); + // //CallWindowProc(oldWndProc, WindowHandle, WM_PAINT, wParam, lParam); + // TabCtrl_AdjustRect(WindowHandle, FALSE, &clientRect); + // ExcludeClipRect(ps.hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom); + //} + // + //if (BufferedPaint = BeginBufferedPaint(ps.hdc, &ps.rcPaint, BPBF_COMPATIBLEBITMAP, NULL, &BufferedHDC)) + //{ + // ThemeWindowRenderTabControl(context, WindowHandle, BufferedHDC, &ps.rcPaint, oldWndProc); + // EndBufferedPaint(BufferedPaint, TRUE); + //} + //else { - //PAINTSTRUCT ps; - //HDC BufferedHDC; - //HPAINTBUFFER BufferedPaint; - // - //if (!BeginPaint(WindowHandle, &ps)) - // break; - // - //DEBUG_BEGINPAINT_RECT(WindowHandle, ps.rcPaint); - // - //{ - // RECT clientRect; - // GetClientRect(WindowHandle, &clientRect); - // //CallWindowProc(oldWndProc, WindowHandle, WM_PAINT, wParam, lParam); - // TabCtrl_AdjustRect(WindowHandle, FALSE, &clientRect); - // ExcludeClipRect(ps.hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom); - //} - // - //if (BufferedPaint = BeginBufferedPaint(ps.hdc, &ps.rcPaint, BPBF_COMPATIBLEBITMAP, NULL, &BufferedHDC)) - //{ - // ThemeWindowRenderTabControl(context, WindowHandle, BufferedHDC, &ps.rcPaint, oldWndProc); - // EndBufferedPaint(BufferedPaint, TRUE); - //} - //else - { - RECT clientRect; - HDC hdc; - HDC bufferDc; - HBITMAP bufferBitmap; - HBITMAP oldBufferBitmap; - - GetClientRect(WindowHandle, &clientRect); - - hdc = GetDC(WindowHandle); - bufferDc = CreateCompatibleDC(hdc); - bufferBitmap = CreateCompatibleBitmap(hdc, clientRect.right, clientRect.bottom); - oldBufferBitmap = SelectBitmap(bufferDc, bufferBitmap); + RECT clientRect; + HDC hdc; + HDC bufferDc; + HBITMAP bufferBitmap; + HBITMAP oldBufferBitmap; - { - RECT clientRect2 = clientRect; - TabCtrl_AdjustRect(WindowHandle, FALSE, &clientRect2); - ExcludeClipRect(hdc, clientRect2.left, clientRect2.top, clientRect2.right, clientRect2.bottom); - } + GetClientRect(WindowHandle, &clientRect); - ThemeWindowRenderTabControl(context, WindowHandle, bufferDc, &clientRect, oldWndProc); + hdc = GetDC(WindowHandle); + bufferDc = CreateCompatibleDC(hdc); + bufferBitmap = CreateCompatibleBitmap(hdc, clientRect.right, clientRect.bottom); + oldBufferBitmap = SelectBitmap(bufferDc, bufferBitmap); - BitBlt(hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom, bufferDc, 0, 0, SRCCOPY); - SelectBitmap(bufferDc, oldBufferBitmap); - DeleteBitmap(bufferBitmap); - DeleteDC(bufferDc); - ReleaseDC(WindowHandle, hdc); + { + RECT clientRect2 = clientRect; + TabCtrl_AdjustRect(WindowHandle, FALSE, &clientRect2); + ExcludeClipRect(hdc, clientRect2.left, clientRect2.top, clientRect2.right, clientRect2.bottom); } - //EndPaint(WindowHandle, &ps); + ThemeWindowRenderTabControl(context, WindowHandle, bufferDc, &clientRect, oldWndProc); + + BitBlt(hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom, bufferDc, 0, 0, SRCCOPY); + SelectBitmap(bufferDc, oldBufferBitmap); + DeleteBitmap(bufferBitmap); + DeleteDC(bufferDc); + ReleaseDC(WindowHandle, hdc); } - goto DefaultWndProc; + + //EndPaint(WindowHandle, &ps); + } + goto DefaultWndProc; } return CallWindowProc(oldWndProc, WindowHandle, uMsg, wParam, lParam); @@ -2767,7 +2785,7 @@ LRESULT CALLBACK PhpThemeWindowListBoxControlSubclassProc( _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam - ) +) { PPHP_THEME_WINDOW_STATUSBAR_CONTEXT context; WNDPROC oldWndProc; @@ -2780,11 +2798,12 @@ LRESULT CALLBACK PhpThemeWindowListBoxControlSubclassProc( switch (uMsg) { case WM_NCDESTROY: - { - PhRemoveWindowContext(WindowHandle, LONG_MAX); - SetWindowLongPtr(WindowHandle, GWLP_WNDPROC, (LONG_PTR)oldWndProc); - } - break; + { + PhRemoveWindowContext(WindowHandle, LONG_MAX); + PhSetWindowProcedure(WindowHandle, oldWndProc); + PhFree(context); + } + break; //case WM_MOUSEMOVE: //case WM_NCMOUSEMOVE: // { @@ -2839,91 +2858,91 @@ LRESULT CALLBACK PhpThemeWindowListBoxControlSubclassProc( // } // break; case WM_NCCALCSIZE: - { - LPNCCALCSIZE_PARAMS ncCalcSize = (NCCALCSIZE_PARAMS*)lParam; + { + LPNCCALCSIZE_PARAMS ncCalcSize = (NCCALCSIZE_PARAMS*)lParam; - CallWindowProc(oldWndProc, WindowHandle, uMsg, wParam, lParam); + CallWindowProc(oldWndProc, WindowHandle, uMsg, wParam, lParam); - PhInflateRect(&ncCalcSize->rgrc[0], 1, 1); - } - return 0; + PhInflateRect(&ncCalcSize->rgrc[0], 1, 1); + } + return 0; case WM_NCPAINT: - { - HDC hdc; - ULONG flags; - RECT clientRect; - RECT windowRect; - HRGN updateRegion; - LONG dpiValue = PhGetWindowDpi(WindowHandle); - INT cxEdge = PhGetSystemMetrics(SM_CXEDGE, dpiValue); - INT cyEdge = PhGetSystemMetrics(SM_CYEDGE, dpiValue); + { + HDC hdc; + ULONG flags; + RECT clientRect; + RECT windowRect; + HRGN updateRegion; + LONG dpiValue = PhGetWindowDpi(WindowHandle); + INT cxEdge = PhGetSystemMetrics(SM_CXEDGE, dpiValue); + INT cyEdge = PhGetSystemMetrics(SM_CYEDGE, dpiValue); + + updateRegion = (HRGN)wParam; - updateRegion = (HRGN)wParam; + GetWindowRect(WindowHandle, &windowRect); - GetWindowRect(WindowHandle, &windowRect); + // draw the scrollbar without the border. + { + HRGN rectregion = CreateRectRgn( + windowRect.left + cxEdge, + windowRect.top + cyEdge, + windowRect.right - cxEdge, + windowRect.bottom - cyEdge + ); - // draw the scrollbar without the border. - { - HRGN rectregion = CreateRectRgn( - windowRect.left + cxEdge, - windowRect.top + cyEdge, - windowRect.right - cxEdge, - windowRect.bottom - cyEdge - ); + if (updateRegion != HRGN_FULL) + CombineRgn(rectregion, rectregion, updateRegion, RGN_AND); + DefWindowProc(WindowHandle, WM_NCPAINT, (WPARAM)rectregion, 0); + DeleteRgn(rectregion); + } - if (updateRegion != HRGN_FULL) - CombineRgn(rectregion, rectregion, updateRegion, RGN_AND); - DefWindowProc(WindowHandle, WM_NCPAINT, (WPARAM)rectregion, 0); - DeleteRgn(rectregion); - } + if (updateRegion == HRGN_FULL) + updateRegion = NULL; - if (updateRegion == HRGN_FULL) - updateRegion = NULL; + flags = DCX_WINDOW | DCX_LOCKWINDOWUPDATE | DCX_USESTYLE; - flags = DCX_WINDOW | DCX_LOCKWINDOWUPDATE | DCX_USESTYLE; + if (updateRegion) + flags |= DCX_INTERSECTRGN | DCX_NODELETERGN; - if (updateRegion) - flags |= DCX_INTERSECTRGN | DCX_NODELETERGN; + if (hdc = GetDCEx(WindowHandle, updateRegion, flags)) + { + PhOffsetRect(&windowRect, -windowRect.left, -windowRect.top); + clientRect = windowRect; + clientRect.left += cxEdge; + clientRect.top += cyEdge; + clientRect.right -= cxEdge; + clientRect.bottom -= cyEdge; - if (hdc = GetDCEx(WindowHandle, updateRegion, flags)) { - PhOffsetRect(&windowRect, -windowRect.left, -windowRect.top); - clientRect = windowRect; - clientRect.left += cxEdge; - clientRect.top += cyEdge; - clientRect.right -= cxEdge; - clientRect.bottom -= cyEdge; + SCROLLBARINFO scrollInfo = { sizeof(SCROLLBARINFO) }; + if (GetScrollBarInfo(WindowHandle, OBJID_VSCROLL, &scrollInfo)) { - SCROLLBARINFO scrollInfo = { sizeof(SCROLLBARINFO) }; - - if (GetScrollBarInfo(WindowHandle, OBJID_VSCROLL, &scrollInfo)) + if ((scrollInfo.rgstate[0] & STATE_SYSTEM_INVISIBLE) == 0) { - if ((scrollInfo.rgstate[0] & STATE_SYSTEM_INVISIBLE) == 0) - { - clientRect.right -= PhGetSystemMetrics(SM_CXVSCROLL, dpiValue); - } + clientRect.right -= PhGetSystemMetrics(SM_CXVSCROLL, dpiValue); } } + } - ExcludeClipRect(hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom); - - if (context->Hot) - { - SetDCBrushColor(hdc, PhThemeWindowHighlightColor); - FrameRect(hdc, &windowRect, PhGetStockBrush(DC_BRUSH)); - } - else - { - SetDCBrushColor(hdc, PhThemeWindowBackground2Color); - FrameRect(hdc, &windowRect, GetSysColorBrush(COLOR_WINDOWFRAME)); - } + ExcludeClipRect(hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom); - ReleaseDC(WindowHandle, hdc); - return TRUE; + if (context->Hot) + { + SetDCBrushColor(hdc, PhThemeWindowHighlightColor); + FrameRect(hdc, &windowRect, PhGetStockBrush(DC_BRUSH)); + } + else + { + SetDCBrushColor(hdc, PhThemeWindowBackground2Color); + FrameRect(hdc, &windowRect, GetSysColorBrush(COLOR_WINDOWFRAME)); } + + ReleaseDC(WindowHandle, hdc); + return TRUE; } - break; + } + break; } return CallWindowProc(oldWndProc, WindowHandle, uMsg, wParam, lParam); @@ -2935,7 +2954,7 @@ VOID ThemeWindowRenderComboBox( _In_ HDC bufferDc, _In_ PRECT clientRect, _In_ WNDPROC WindowProcedure - ) +) { RECT bufferRect = { @@ -2975,7 +2994,7 @@ VOID ThemeWindowRenderComboBox( NULL, TS_TRUE, &dropdownSize - ); + ); bufferRect.left = clientRect->right - dropdownSize.cy; @@ -2986,7 +3005,7 @@ VOID ThemeWindowRenderComboBox( CBXSR_DISABLED, &bufferRect, NULL - ); + ); bufferRect.left = 0; } @@ -3022,43 +3041,7 @@ VOID ThemeWindowRenderComboBox( (UINT)PhCountStringZ(comboText), &bufferRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS - ); - } - } -} - -VOID ThemeWindowComboBoxExcludeRect( - _In_ PPHP_THEME_WINDOW_COMBO_CONTEXT Context, - _In_ HWND WindowHandle, - _In_ HDC Hdc, - _In_ PRECT clientRect, - _In_ WNDPROC WindowProcedure - ) -{ - LONG_PTR windowStyle = PhGetWindowStyle(WindowHandle); - - if ((windowStyle & CBS_DROPDOWNLIST) != CBS_DROPDOWNLIST || (windowStyle & CBS_DROPDOWN) != CBS_DROPDOWN) - { - COMBOBOXINFO info = { sizeof(COMBOBOXINFO) }; - - if (CallWindowProc(WindowProcedure, WindowHandle, CB_GETCOMBOBOXINFO, 0, (LPARAM)&info)) - { - //INT borderSize = 0; - //if (Context->ThemeHandle) - //{ - // if (PhGetThemeInt(Context->ThemeHandle, 0, 0, TMT_BORDERSIZE, &borderSize)) - // { - // borderSize = borderSize * 2; - // } - //} - - ExcludeClipRect( - Hdc, - info.rcItem.left, - info.rcItem.top, - info.rcItem.right, - info.rcItem.bottom - ); + ); } } } @@ -3068,7 +3051,7 @@ LRESULT CALLBACK PhpThemeWindowComboBoxControlSubclassProc( _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam - ) +) { PPHP_THEME_WINDOW_COMBO_CONTEXT context; WNDPROC oldWndProc; @@ -3081,9 +3064,9 @@ LRESULT CALLBACK PhpThemeWindowComboBoxControlSubclassProc( switch (uMsg) { case WM_NCDESTROY: - { - PhRemoveWindowContext(WindowHandle, LONG_MAX); - SetWindowLongPtr(WindowHandle, GWLP_WNDPROC, (LONG_PTR)oldWndProc); + { + PhRemoveWindowContext(WindowHandle, LONG_MAX); + PhSetWindowProcedure(WindowHandle, oldWndProc); if (context->ThemeHandle) { @@ -3143,14 +3126,45 @@ LRESULT CALLBACK PhpThemeWindowComboBoxControlSubclassProc( HBITMAP bufferBitmap; HBITMAP oldBufferBitmap; + LONG_PTR windowStyle = PhGetWindowStyle(WindowHandle); GetClientRect(WindowHandle, &clientRect); - hdc = GetDC(WindowHandle); + + if ((windowStyle & CBS_DROPDOWNLIST) != CBS_DROPDOWNLIST || (windowStyle & CBS_DROPDOWN) != CBS_DROPDOWN) + { + COMBOBOXINFO info = { sizeof(COMBOBOXINFO) }; + RECT windowRect; + RECT listRect; + + if (CallWindowProc(oldWndProc, WindowHandle, CB_GETCOMBOBOXINFO, 0, (LPARAM)&info) && info.hwndList) + { + GetWindowRect(WindowHandle, &windowRect); + GetWindowRect(info.hwndList, &listRect); + clientRect.bottom -= (windowRect.bottom - listRect.bottom); + + //INT borderSize = 0; + //if (Context->ThemeHandle) + //{ + // if (PhGetThemeInt(Context->ThemeHandle, 0, 0, TMT_BORDERSIZE, &borderSize)) + // { + // borderSize = borderSize * 2; + // } + //} + + ExcludeClipRect( + hdc, + info.rcItem.left, + info.rcItem.top, + info.rcItem.right, + info.rcItem.bottom + ); + } + } + bufferDc = CreateCompatibleDC(hdc); bufferBitmap = CreateCompatibleBitmap(hdc, clientRect.right, clientRect.bottom); oldBufferBitmap = SelectBitmap(bufferDc, bufferBitmap); - ThemeWindowComboBoxExcludeRect(context, WindowHandle, hdc, &clientRect, oldWndProc); ThemeWindowRenderComboBox(context, WindowHandle, bufferDc, &clientRect, oldWndProc); BitBlt(hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom, bufferDc, 0, 0, SRCCOPY); @@ -3185,10 +3199,12 @@ LRESULT CALLBACK PhpThemeWindowACLUISubclassProc( switch (uMsg) { - case WM_VSCROLL: - case WM_MOUSEWHEEL: - InvalidateRect(WindowHandle, NULL, FALSE); - break; + case WM_NCDESTROY: + { + PhRemoveWindowContext(WindowHandle, LONG_MAX); + PhSetWindowProcedure(WindowHandle, oldWndProc); + } + break; case WM_NOTIFY: { LPNMHDR data = (LPNMHDR)lParam; @@ -3200,8 +3216,8 @@ LRESULT CALLBACK PhpThemeWindowACLUISubclassProc( if (customDraw->dwDrawStage == CDDS_PREPAINT && !(customDraw->uItemState & CDIS_FOCUS)) { - if (!GetClassName(customDraw->hdr.hwndFrom, className, RTL_NUMBER_OF(className))) - className[0] = UNICODE_NULL; + GETCLASSNAME_OR_NULL(customDraw->hdr.hwndFrom, className); + if (PhEqualStringZ(className, WC_BUTTON, FALSE)) { HDC hdc = GetDC(WindowHandle); @@ -3215,11 +3231,9 @@ LRESULT CALLBACK PhpThemeWindowACLUISubclassProc( } } break; - case WM_NCDESTROY: - { - PhRemoveWindowContext(WindowHandle, LONG_MAX); - SetWindowLongPtr(WindowHandle, GWLP_WNDPROC, (LONG_PTR)oldWndProc); - } + case WM_VSCROLL: + case WM_MOUSEWHEEL: + InvalidateRect(WindowHandle, NULL, FALSE); break; case WM_ERASEBKGND: { diff --git a/phlib/treenew.c b/phlib/treenew.c index e55d000952e1..23a3696ce06d 100644 --- a/phlib/treenew.c +++ b/phlib/treenew.c @@ -5363,7 +5363,8 @@ VOID PhTnpPaint( RECT tempRect; BLENDFUNCTION blendFunction; - SetTextColor(hdc, PhThemeWindowTextColor); + // Fix ForeColor for theme, previously it was always white. Plus 90-100 brightness adjustments seems fine for good contrast. (Dart Vanya) + SetTextColor(hdc, !node->UseAutoForeColor && node->s.DrawForeColor != 0 ? PhMakeColorBrighter(node->s.DrawForeColor, 95) : PhThemeWindowTextColor); SetDCBrushColor(hdc, PhThemeWindowBackgroundColor); FillRect(hdc, &rowRect, PhGetStockBrush(DC_BRUSH)); diff --git a/plugins/ExtendedTools/disktab.c b/plugins/ExtendedTools/disktab.c index a88cba0dfcf2..a3e4e405e42a 100644 --- a/plugins/ExtendedTools/disktab.c +++ b/plugins/ExtendedTools/disktab.c @@ -95,19 +95,13 @@ BOOLEAN EtpDiskPageCallback( 0, Parameter2, NULL, - NULL, + PluginInstance->DllBase, &treelistCreateParams ); if (!hwnd) return FALSE; - if (PhIsThemeSupportEnabled()) - { - PhInitializeWindowTheme(hwnd, TRUE); // HACK (dmex) - TreeNew_ThemeSupport(hwnd, TRUE); - } - DiskTreeNewCreated = TRUE; DiskNodeHashtable = PhCreateHashtable( @@ -120,6 +114,8 @@ BOOLEAN EtpDiskPageCallback( EtInitializeDiskTreeList(hwnd); + PhInitializeWindowTheme(hwnd, PhIsThemeSupportEnabled()); + //if (!EtEtwEnabled) // always show status (dmex) { if (EtEtwStatus != ERROR_SUCCESS) @@ -262,7 +258,7 @@ VOID EtInitializeDiskTreeList( { DiskTreeNewHandle = WindowHandle; - PhSetControlTheme(DiskTreeNewHandle, !PhIsThemeSupportEnabled() ? L"explorer" : L"DarkMode_Explorer"); + PhSetControlTheme(DiskTreeNewHandle, L"explorer"); TreeNew_SetRedraw(WindowHandle, FALSE); SendMessage(TreeNew_GetTooltips(DiskTreeNewHandle), TTM_SETDELAYTIME, TTDT_AUTOPOP, 0x7fff); TreeNew_SetCallback(WindowHandle, EtpDiskTreeNewCallback, NULL); diff --git a/plugins/ExtendedTools/fwtab.c b/plugins/ExtendedTools/fwtab.c index 2c19f5256203..585f6cd52718 100644 --- a/plugins/ExtendedTools/fwtab.c +++ b/plugins/ExtendedTools/fwtab.c @@ -83,16 +83,12 @@ BOOLEAN FwTabPageCallback( FwTreeNewCreated = TRUE; - if (PhIsThemeSupportEnabled()) - { - PhInitializeWindowTheme(hwnd, TRUE); // HACK (dmex) - TreeNew_ThemeSupport(hwnd, TRUE); - } - PhInitializeProviderEventQueue(&FwNetworkEventQueue, 100); InitializeFwTreeList(hwnd); + PhInitializeWindowTheme(hwnd, PhIsThemeSupportEnabled()); + if (PhGetOwnTokenAttributes().Elevated) { EtFwStatus = EtFwMonitorInitialize(); @@ -253,7 +249,7 @@ VOID InitializeFwTreeList( InitializeFwTreeListDpi(FwTreeNewHandle); - PhSetControlTheme(FwTreeNewHandle, !PhIsThemeSupportEnabled() ? L"explorer" : L"DarkMode_Explorer"); + PhSetControlTheme(FwTreeNewHandle, L"explorer"); TreeNew_SetRedraw(FwTreeNewHandle, FALSE); TreeNew_SetCallback(FwTreeNewHandle, FwTreeNewCallback, NULL); diff --git a/plugins/ExtendedTools/objprp.c b/plugins/ExtendedTools/objprp.c index cbee70871ca9..4ad243945fab 100644 --- a/plugins/ExtendedTools/objprp.c +++ b/plugins/ExtendedTools/objprp.c @@ -2139,6 +2139,8 @@ INT_PTR CALLBACK EtpWinStaPageDlgProc( PhAddListViewColumn(context->ListViewHandle, ETDTLVC_IO, ETDTLVC_IO, ETDTLVC_IO, LVCFMT_LEFT, 45, L"Input"); PhSetExtendedListView(context->ListViewHandle); ExtendedListView_SetSort(context->ListViewHandle, 0, NoSortOrder); + PhInitializeLayoutManager(&context->LayoutManager, hwndDlg); + PhAddLayoutItem(&context->LayoutManager, context->ListViewHandle, NULL, PH_ANCHOR_ALL); ExtendedListView_SetRedraw(context->ListViewHandle, FALSE); @@ -2165,6 +2167,12 @@ INT_PTR CALLBACK EtpWinStaPageDlgProc( PhInitializeWindowTheme(hwndDlg, PhIsThemeSupportEnabled()); } break; + case WM_SIZE: + { + PhLayoutManagerLayout(&context->LayoutManager); + ExtendedListView_SetColumnWidth(context->ListViewHandle, 0, ELVSCW_AUTOSIZE_REMAININGSPACE); + } + break; case WM_DESTROY: { INT index = INT_ERROR; @@ -2185,6 +2193,7 @@ INT_PTR CALLBACK EtpWinStaPageDlgProc( break; case WM_NCDESTROY: { + PhDeleteLayoutManager(&context->LayoutManager); PhRemoveWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT); PhFree(context); } diff --git a/plugins/HardwareDevices/deviceprops.c b/plugins/HardwareDevices/deviceprops.c index 96f4e8a6fbad..0857301f5733 100644 --- a/plugins/HardwareDevices/deviceprops.c +++ b/plugins/HardwareDevices/deviceprops.c @@ -245,10 +245,7 @@ INT_PTR CALLBACK DevicePropGeneralDlgProc( ExtendedListView_SetColumnWidth(context->GeneralListViewHandle, 1, ELVSCW_AUTOSIZE_REMAININGSPACE); } - if (PhIsThemeSupportEnabled()) // TODO: Required for compat (dmex) - PhInitializeWindowTheme(GetParent(hwndDlg), PhIsThemeSupportEnabled()); - else - PhInitializeWindowTheme(hwndDlg, FALSE); + PhInitializeWindowTheme(GetParent(hwndDlg), PhIsThemeSupportEnabled()); } break; case WM_DESTROY: diff --git a/plugins/HardwareDevices/devicetree.c b/plugins/HardwareDevices/devicetree.c index e6db43a084d7..28fdcf0249dc 100644 --- a/plugins/HardwareDevices/devicetree.c +++ b/plugins/HardwareDevices/devicetree.c @@ -1351,12 +1351,7 @@ VOID DevicesTreeInitialize( TreeNew_SetRowHeight(DeviceTreeHandle, treelistCustomRowSize); } - if (PhIsThemeSupportEnabled()) - { - PhInitializeWindowTheme(DeviceTreeHandle, TRUE); - PhSetControlTheme(DeviceTreeHandle, L"DarkMode_Explorer"); - TreeNew_ThemeSupport(DeviceTreeHandle, TRUE); - } + PhInitializeWindowTheme(DeviceTreeHandle, PhIsThemeSupportEnabled()); TreeNew_SetTriState(DeviceTreeHandle, TRUE); TreeNew_SetRedraw(DeviceTreeHandle, TRUE); diff --git a/plugins/HardwareDevices/diskdetails.c b/plugins/HardwareDevices/diskdetails.c index b4d59c81010c..4b58cad80b3c 100644 --- a/plugins/HardwareDevices/diskdetails.c +++ b/plugins/HardwareDevices/diskdetails.c @@ -662,11 +662,8 @@ INT_PTR CALLBACK DiskDeviceFileSystemDetailsDlgProc( // Note: Load settings after querying devices. (dmex) PhLoadListViewColumnsFromSetting(SETTING_NAME_DISK_COUNTERS_COLUMNS, context->ListViewHandle); - if (PhIsThemeSupportEnabled()) // TODO: Required for compat (dmex) - PhInitializeWindowTheme(GetParent(hwndDlg), PhIsThemeSupportEnabled()); - else - PhInitializeWindowTheme(hwndDlg, FALSE); - + PhInitializeWindowTheme(GetParent(hwndDlg), PhIsThemeSupportEnabled()); + PhRegisterCallback( PhGetGeneralCallback(GeneralCallbackProcessProviderUpdatedEvent), DiskDeviceProcessesUpdatedHandler, diff --git a/plugins/ToolStatus/main.c b/plugins/ToolStatus/main.c index be37ab273de0..be09bfd8e0b5 100644 --- a/plugins/ToolStatus/main.c +++ b/plugins/ToolStatus/main.c @@ -1741,6 +1741,10 @@ VOID UpdateCachedSettings( IconSingleClick = !!PhGetIntegerSetting(L"IconSingleClick"); EnableAvxSupport = !!PhGetIntegerSetting(L"EnableAvxSupport"); EnableGraphMaxScale = !!PhGetIntegerSetting(L"EnableGraphMaxScale"); + BOOLEAN oldTheme = EnableThemeSupport; + EnableThemeSupport = PhIsThemeSupportEnabled(); + if (EnableThemeSupport != oldTheme) + InvalidateRect(RebarHandle, NULL, TRUE); // diff --git a/plugins/WindowExplorer/wndprp.c b/plugins/WindowExplorer/wndprp.c index 7dd10a49d6cf..5fcd35c4fba7 100644 --- a/plugins/WindowExplorer/wndprp.c +++ b/plugins/WindowExplorer/wndprp.c @@ -1466,10 +1466,7 @@ INT_PTR CALLBACK WepWindowGeneralDlgProc( ExtendedListView_SetColumnWidth(context->ListViewHandle, 1, ELVSCW_AUTOSIZE_REMAININGSPACE); } - if (PhIsThemeSupportEnabled()) // TODO: Required for compat (dmex) - PhInitializeWindowTheme(GetParent(hwndDlg), PhIsThemeSupportEnabled()); - else - PhInitializeWindowTheme(hwndDlg, FALSE); + PhInitializeWindowTheme(GetParent(hwndDlg), PhIsThemeSupportEnabled()); } break; case WM_DESTROY: diff --git a/plugins/WindowExplorer/wndtree.c b/plugins/WindowExplorer/wndtree.c index 8481768a3b70..1fa1d1075e72 100644 --- a/plugins/WindowExplorer/wndtree.c +++ b/plugins/WindowExplorer/wndtree.c @@ -474,7 +474,7 @@ BOOLEAN NTAPI WepWindowTreeNewCallback( node = (PWE_WINDOW_NODE)getNodeColor->Node; if (!node->WindowVisible) - getNodeColor->ForeColor = RGB(0x55, 0x55, 0x55); + getNodeColor->ForeColor = PhGetIntegerSetting(L"ColorServiceStop"); if (node->WindowMessageOnly) { diff --git a/tools/peview/include/peview.h b/tools/peview/include/peview.h index fc24876732ff..22c826de2cf4 100644 --- a/tools/peview/include/peview.h +++ b/tools/peview/include/peview.h @@ -170,7 +170,7 @@ VOID PvSaveSettings( ); VOID PvUpdateCachedSettings( - _In_ BOOLEAN ApplyTheme + VOID ); VOID PvShowOptionsWindow( @@ -862,4 +862,8 @@ EXTERN_C HRESULT PvClrImageEnumTables( _In_ PVOID Context ); +NTSTATUS NTAPI PvReInitializeThemeThread( + _In_ PVOID Context + ); + #endif diff --git a/tools/peview/main.c b/tools/peview/main.c index 4617a134f7d8..23ad7fe97786 100644 --- a/tools/peview/main.c +++ b/tools/peview/main.c @@ -120,7 +120,7 @@ INT WINAPI wWinMain( PhGuiSupportInitialization(); PhSettingsInitialization(); PvInitializeSettings(); - PvInitializeSuperclassControls(); + PhInitializeSuperclassControls(); PhShowWarning2( NULL, L"Warning.", diff --git a/tools/peview/options.c b/tools/peview/options.c index c55250a01de0..d138188b7b17 100644 --- a/tools/peview/options.c +++ b/tools/peview/options.c @@ -18,6 +18,7 @@ typedef enum _PHP_OPTIONS_INDEX PHP_OPTIONS_INDEX_ENABLE_LEGACY_TABS, PHP_OPTIONS_INDEX_ENABLE_THEME_BORDER, PHP_OPTIONS_INDEX_ENABLE_LASTTAB_SUPPORT, + PHP_OPTIONS_INDEX_ENABLE_STREAM_MODE } PHP_OPTIONS_GENERAL_INDEX; typedef struct _PVP_PE_OPTIONS_CONTEXT @@ -142,6 +143,7 @@ VOID PvLoadGeneralPage( PhAddListViewItem(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_LEGACY_TABS, L"Enable legacy properties window", NULL); PhAddListViewItem(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_BORDER, L"Enable view borders", NULL); PhAddListViewItem(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_LASTTAB_SUPPORT, L"Remember last selected window", NULL); + PhAddListViewItem(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_STREAM_MODE, L"Enable streamer mode (disable window capture)", NULL); //SetLvItemCheckForSetting(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_WARNINGS, L"EnableWarnings"); //SetLvItemCheckForSetting(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_PLUGINS, L"EnablePlugins"); @@ -152,6 +154,7 @@ VOID PvLoadGeneralPage( SetLvItemCheckForSetting(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_LEGACY_TABS, L"EnableLegacyPropertiesDialog"); SetLvItemCheckForSetting(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_BORDER, L"EnableTreeListBorder"); SetLvItemCheckForSetting(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_LASTTAB_SUPPORT, L"MainWindowPageRestoreEnabled"); + SetLvItemCheckForSetting(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_STREAM_MODE, L"EnableStreamerMode"); } VOID PvGeneralPageSave( @@ -175,16 +178,30 @@ VOID PvGeneralPageSave( //SetSettingForLvItemCheck(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_WARNINGS, L"EnableWarnings"); //SetSettingForLvItemCheckRestartRequired(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_PLUGINS, L"EnablePlugins"); //SetSettingForLvItemCheck(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_UNDECORATE_SYMBOLS, L"DbgHelpUndecorate"); - SetSettingForLvItemCheckRestartRequired(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_SUPPORT, L"EnableThemeSupport"); - SetSettingForLvItemCheckRestartRequired(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_WINDOWS_THEME, L"EnableThemeUseWindowsTheme"); + SetSettingForLvItemCheck(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_SUPPORT, L"EnableThemeSupport"); + SetSettingForLvItemCheck(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_WINDOWS_THEME, L"EnableThemeUseWindowsTheme"); //SetSettingForLvItemCheck(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_START_ASADMIN, L"EnableStartAsAdmin"); SetSettingForLvItemCheckRestartRequired(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_LASTTAB_SUPPORT, L"MainWindowPageRestoreEnabled"); SetSettingForLvItemCheckRestartRequired(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_LEGACY_TABS, L"EnableLegacyPropertiesDialog"); SetSettingForLvItemCheckRestartRequired(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_BORDER, L"EnableTreeListBorder"); + SetSettingForLvItemCheck(Context->ListViewHandle, PHP_OPTIONS_INDEX_ENABLE_STREAM_MODE, L"EnableStreamerMode"); - PvUpdateCachedSettings(FALSE); + BOOLEAN oldTheme = PhEnableThemeSupport; + BOOLEAN oldStreamerMode = PhEnableStreamerMode; + + PvUpdateCachedSettings(); PvSaveSettings(); + if (PhEnableThemeSupport != oldTheme) + { + PhReInitializeTheme(PhEnableThemeSupport); + } + + if (PhEnableStreamerMode != oldStreamerMode) + { + PhReInitializeStreamerMode(PhEnableStreamerMode); + } + if (RestartRequired) { if (PhShowMessage2( diff --git a/tools/peview/peprp.c b/tools/peview/peprp.c index ff2ace39a7da..d5afbb4d4223 100644 --- a/tools/peview/peprp.c +++ b/tools/peview/peprp.c @@ -2249,6 +2249,12 @@ INT_PTR CALLBACK PvPeGeneralDlgProc( return (INT_PTR)PhGetStockBrush(DC_BRUSH); } break; + case WM_SETTINGCHANGE: + if (HANDLE_COLORSCHEMECHANGE_MESSAGE(wParam, lParam, L"EnableThemeSupport", L"EnableThemeUseWindowsTheme")) + { + PhCreateThread2(PvReInitializeThemeThread, NULL); + } + break; } return FALSE; diff --git a/tools/peview/peprpwnd.c b/tools/peview/peprpwnd.c index 3d049586f0fd..16b65b226fc8 100644 --- a/tools/peview/peprpwnd.c +++ b/tools/peview/peprpwnd.c @@ -983,11 +983,38 @@ INT_PTR CALLBACK PvTabWindowDialogProc( } } break; + case WM_SETTINGCHANGE: + if (HANDLE_COLORSCHEMECHANGE_MESSAGE(wParam, lParam, L"EnableThemeSupport", L"EnableThemeUseWindowsTheme")) + { + PhCreateThread2(PvReInitializeThemeThread, NULL); + } + break; } return FALSE; } +NTSTATUS NTAPI PvReInitializeThemeThread( + _In_ PVOID Context + ) +{ + BOOLEAN currentTheme; + + //currentTheme = PhShouldAppsUseDarkMode(); + currentTheme = PhGetAppsUseLightTheme(); + + dprintf("PvReInitializeThemeThread: currentTheme = %d, PhEnableThemeSupport = %d\r\n", currentTheme, PhEnableThemeSupport); + + if (PhEnableThemeSupport != currentTheme) + { + PhEnableThemeSupport = currentTheme; + + PhReInitializeTheme(PhEnableThemeSupport); + }; + + return STATUS_SUCCESS; +} + VOID PvTabWindowOnSize( VOID ) diff --git a/tools/peview/searchbox.c b/tools/peview/searchbox.c index d3d23e92e649..bf7d584584dc 100644 --- a/tools/peview/searchbox.c +++ b/tools/peview/searchbox.c @@ -24,10 +24,14 @@ VOID PvCreateSearchControl( ParentWindowHandle, WindowHandle, BannerText, - PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_DARK), - PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_DARK), - PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_DARK), - PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_DARK), + MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_LIGHT), + MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_LIGHT), + MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_LIGHT), + MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_LIGHT), + MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_DARK), + MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_DARK), + MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_DARK), + MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_DARK), L"SearchControlRegex", L"SearchControlCaseSensitive", Callback, diff --git a/tools/peview/settings.c b/tools/peview/settings.c index 69e366c2ceab..34a2a412da1c 100644 --- a/tools/peview/settings.c +++ b/tools/peview/settings.c @@ -118,20 +118,35 @@ VOID PvAddDefaultSettings( } VOID PvUpdateCachedSettings( - _In_ BOOLEAN ApplyTheme + VOID ) { PhMaxSizeUnit = PhGetIntegerSetting(L"MaxSizeUnit"); PhEnableSecurityAdvancedDialog = !!PhGetIntegerSetting(L"EnableSecurityAdvancedDialog"); - if (ApplyTheme) - PhEnableThemeSupport = PhIsThemeSupportEnabled(); + PhEnableThemeSupport = PhIsThemeSupportEnabled(); PhThemeWindowForegroundColor = PhGetIntegerSetting(L"ThemeWindowForegroundColor"); + COLORREF oldPhThemeWindowBackgroundColor = PhThemeWindowBackgroundColor; PhThemeWindowBackgroundColor = PhGetIntegerSetting(L"ThemeWindowBackgroundColor"); PhThemeWindowBackground2Color = PhGetIntegerSetting(L"ThemeWindowBackground2Color"); PhThemeWindowHighlightColor = PhGetIntegerSetting(L"ThemeWindowHighlightColor"); PhThemeWindowHighlight2Color = PhGetIntegerSetting(L"ThemeWindowHighlight2Color"); PhThemeWindowTextColor = PhGetIntegerSetting(L"ThemeWindowTextColor"); PhEnableThemeListviewBorder = !!PhGetIntegerSetting(L"TreeListBorderEnable"); + PhEnableThemeNativeButtons = !!PhGetIntegerSetting(L"EnableThemeNativeButtons"); + PhEnableThemeTabBorders = !!PhGetIntegerSetting(L"EnableThemeTabBorders"); + PhEnableThemeAcrylicSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicSupport"); + PhEnableThemeAcrylicWindowSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicWindowSupport"); + PhEnableStreamerMode = !!PhGetIntegerSetting(L"EnableStreamerMode"); + + PH_THEME_SET_PREFFEREDAPPMODE(L"EnableThemeSupport", L"EnableThemeUseWindowsTheme"); + + PhEnableThemeSupport = PH_THEME_GET_GENERAL_SWITCH(L"EnableThemeSupport"); + + if (oldPhThemeWindowBackgroundColor != PhThemeWindowBackgroundColor && PhThemeWindowBackgroundBrush) + { + DeleteBrush(PhThemeWindowBackgroundBrush); + PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor); + } } VOID PvInitializeSettings( @@ -219,7 +234,7 @@ VOID PvInitializeSettings( } } - PvUpdateCachedSettings(TRUE); + PvUpdateCachedSettings(); } VOID PvSaveSettings(