1919#include " CommonDef.h"
2020#include " wil.h"
2121#include < shellscalingapi.h>
22+ #include " ../Helper/Helper.h" // For DrawTextWithGlow
2223#pragma comment(lib, "shcore.lib")
2324
2425namespace MDWMBlurGlassExt ::TitleTextTweaker
@@ -173,34 +174,53 @@ namespace MDWMBlurGlassExt::TitleTextTweaker
173174 lprc->right -= g_textGlowSize;
174175 lprc->bottom -= g_textGlowSize;
175176
176- DTTOPTS options
177- {
178- sizeof (DTTOPTS ),
179- DTT_TEXTCOLOR | DTT_COMPOSITED | DTT_CALLBACK | DTT_GLOWSIZE ,
180- GetTextColor (hdc),
181- 0 ,
182- 0 ,
183- 0 ,
184- {},
185- 0 ,
186- 0 ,
187- 0 ,
188- 0 ,
189- FALSE ,
177+ // Get the current text color and calculate the brightness using YIQ formula
178+ COLORREF textColor = GetTextColor (hdc);
179+ int luminance = (GetRValue (textColor) * 299 + GetGValue (textColor) * 587 + GetBValue (textColor) * 114 ) / 1000 ;
180+
181+ UINT crGlow = (luminance > 128 ) ? RGB (128 , 128 , 128 ) : RGB (255 , 255 , 255 );
182+ UINT nGlowIntensity = 255 ;
183+
184+ // Prioritize calling uxtheme's inner function number 126 to render realistic glow.
185+ HRESULT hr = MDWMBlurGlassExt::DrawTextWithGlow (
186+ hdc,
187+ lpchText,
188+ cchText,
189+ lprc,
190+ format,
191+ textColor,
192+ crGlow,
190193 g_textGlowSize,
194+ nGlowIntensity,
195+ TRUE ,
191196 drawTextCallback,
192197 (LPARAM )&result
193- };
194- wil::unique_htheme hTheme{ OpenThemeData (nullptr , L" Composited::Window" ) };
198+ );
195199
196- if (hTheme)
200+ // If the extraction of the undocumented function fails, revert to the original DrawThemeTextEx as a fallback rendering method.
201+ if (FAILED (hr))
197202 {
198- LOG_IF_FAILED (DrawThemeTextEx (hTheme.get (), hdc, 0 , 0 , lpchText, cchText, format, lprc, &options));
199- }
200- else
201- {
202- LOG_HR_IF_NULL (E_FAIL , hTheme);
203- result = g_funDrawTextW (hdc, lpchText, cchText, lprc, format);
203+ DTTOPTS options
204+ {
205+ sizeof (DTTOPTS ),
206+ DTT_TEXTCOLOR | DTT_COMPOSITED | DTT_CALLBACK | DTT_GLOWSIZE ,
207+ textColor,
208+ 0 , 0 , 0 , {}, 0 , 0 , 0 , 0 , FALSE ,
209+ g_textGlowSize,
210+ drawTextCallback,
211+ (LPARAM )&result
212+ };
213+ wil::unique_htheme hTheme{ OpenThemeData (nullptr , L" Composited::Window" ) };
214+
215+ if (hTheme)
216+ {
217+ LOG_IF_FAILED (DrawThemeTextEx (hTheme.get (), hdc, 0 , 0 , lpchText, cchText, format, lprc, &options));
218+ }
219+ else
220+ {
221+ LOG_HR_IF_NULL (E_FAIL , hTheme);
222+ result = g_funDrawTextW (hdc, lpchText, cchText, lprc, format);
223+ }
204224 }
205225
206226 lprc->left -= g_textGlowSize;
@@ -211,6 +231,7 @@ namespace MDWMBlurGlassExt::TitleTextTweaker
211231 return result;
212232 }
213233
234+
214235 HRESULT MyCreateBitmapFromHBITMAP (IWICImagingFactory2* This, HBITMAP hBitmap, HPALETTE hPalette,
215236 WICBitmapAlphaChannelOption options, IWICBitmap** ppIBitmap)
216237 {
0 commit comments