comparison win/dw.c @ 2140:b6e09fb597aa

Win: Import and use some undocumented APIs to get the titlebar text color. Probably will use these to get other dark mode colors in _DW_GetSysColor().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 12 Jul 2020 22:18:36 +0000
parents b1521c8f7861
children 709f8bfa711f
comparison
equal deleted inserted replaced
2139:b1521c8f7861 2140:b6e09fb597aa
215 HRESULT (WINAPI *_BufferedPaintSetAlpha)(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha) = 0; 215 HRESULT (WINAPI *_BufferedPaintSetAlpha)(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha) = 0;
216 HRESULT (WINAPI *_DrawThemeTextEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwFlags, LPRECT pRect, const DTTOPTS *pOptions) = 0; 216 HRESULT (WINAPI *_DrawThemeTextEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwFlags, LPRECT pRect, const DTTOPTS *pOptions) = 0;
217 HRESULT (WINAPI *_EndBufferedPaint)(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget) = 0; 217 HRESULT (WINAPI *_EndBufferedPaint)(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget) = 0;
218 HRESULT (WINAPI *_CloseThemeData)(HTHEME hTheme) = 0; 218 HRESULT (WINAPI *_CloseThemeData)(HTHEME hTheme) = 0;
219 HRESULT (WINAPI *_GetThemeSysFont)(HTHEME hTheme, int iFontId, LOGFONTW *plf) = 0; 219 HRESULT (WINAPI *_GetThemeSysFont)(HTHEME hTheme, int iFontId, LOGFONTW *plf) = 0;
220 DWORD(WINAPI *_GetImmersiveColorFromColorSetEx)(UINT dwImmersiveColorSet, UINT dwImmersiveColorType, BOOL bIgnoreHighContrast, UINT dwHighContrastCacheMode) = 0;
221 int (WINAPI *_GetImmersiveColorTypeFromName)(const WCHAR *name) = 0;
222 int (WINAPI *_GetImmersiveUserColorSetPreference)(BOOL bForceCheckRegistry, BOOL bSkipCheckOnFail) = 0;
220 BOOL _dw_composition = FALSE; 223 BOOL _dw_composition = FALSE;
221 COLORREF _dw_transparencykey = RGB(200,201,202); 224 COLORREF _dw_transparencykey = RGB(200,201,202);
222 HANDLE hdwm = 0; 225 HANDLE hdwm = 0;
223 #endif 226 #endif
224 /* Aero related but separate functions and handles */ 227 /* Aero related but separate functions and handles */
915 #define RECTHEIGHT(rc) (rc.bottom - rc.top) 918 #define RECTHEIGHT(rc) (rc.bottom - rc.top)
916 919
917 /* Our function to draw the titlebar in dark mode */ 920 /* Our function to draw the titlebar in dark mode */
918 void _DW_DrawDarkModeTitleBar(HWND hWnd, HDC hdc) 921 void _DW_DrawDarkModeTitleBar(HWND hWnd, HDC hdc)
919 { 922 {
920 if(_OpenThemeData && _CloseThemeData && _DrawThemeTextEx && _GetThemeSysFont) 923 if(_OpenThemeData && _CloseThemeData && _DrawThemeTextEx && _GetThemeSysFont &&
924 _GetImmersiveColorFromColorSetEx && _GetImmersiveColorTypeFromName && _GetImmersiveUserColorSetPreference)
921 { 925 {
922 HTHEME hTheme = _OpenThemeData(NULL, L"CompositedWindow::Window"); 926 HTHEME hTheme = _OpenThemeData(NULL, L"CompositedWindow::Window");
923 RECT rcClient; 927 RECT rcClient;
924 928
925 GetClientRect(hWnd, &rcClient); 929 GetClientRect(hWnd, &rcClient);
953 LOGFONT lgFont; 957 LOGFONT lgFont;
954 HFONT hFontOld = NULL; 958 HFONT hFontOld = NULL;
955 RECT rcPaint = rcClient; 959 RECT rcPaint = rcClient;
956 TCHAR *tempbuf; 960 TCHAR *tempbuf;
957 int len; 961 int len;
962 DWORD nColor = _GetImmersiveColorFromColorSetEx(_GetImmersiveUserColorSetPreference(FALSE, FALSE),
963 _GetImmersiveColorTypeFromName(L"ImmersiveApplicationText"), FALSE, 0);
958 964
959 /* Setup the theme drawing options. */ 965 /* Setup the theme drawing options. */
960 DTTOPTS DttOpts = {sizeof(DTTOPTS)}; 966 DTTOPTS DttOpts = {sizeof(DTTOPTS)};
961 DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE; 967 DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
962 DttOpts.iGlowSize = 15; 968 DttOpts.iGlowSize = 15;
969 DttOpts.crText = RGB(0xFF & nColor, (0xFF00 & nColor) >> 8, (0xFF0000 & nColor) >> 16);
963 970
964 /* Select a font. */ 971 /* Select a font. */
965 if(_GetThemeSysFont(hTheme, 801 /*TMT_CAPTIONFONT*/, &lgFont) == S_OK) 972 if(_GetThemeSysFont(hTheme, 801 /*TMT_CAPTIONFONT*/, &lgFont) == S_OK)
966 { 973 {
967 HFONT hFont = CreateFontIndirect(&lgFont); 974 HFONT hFont = CreateFontIndirect(&lgFont);
4554 _DwmDefWindowProc = (BOOL (WINAPI *)(HWND, UINT, WPARAM, LPARAM, LRESULT *))GetProcAddress(hdwm, "DwmDefWindowProc"); 4561 _DwmDefWindowProc = (BOOL (WINAPI *)(HWND, UINT, WPARAM, LPARAM, LRESULT *))GetProcAddress(hdwm, "DwmDefWindowProc");
4555 if((_DwmIsCompositionEnabled = (HRESULT (WINAPI *)(BOOL *))GetProcAddress(hdwm, "DwmIsCompositionEnabled"))) 4562 if((_DwmIsCompositionEnabled = (HRESULT (WINAPI *)(BOOL *))GetProcAddress(hdwm, "DwmIsCompositionEnabled")))
4556 _DwmIsCompositionEnabled(&_dw_composition); 4563 _DwmIsCompositionEnabled(&_dw_composition);
4557 _OpenThemeData = (HTHEME (WINAPI *)(HWND, LPCWSTR))GetProcAddress(huxtheme, "OpenThemeData"); 4564 _OpenThemeData = (HTHEME (WINAPI *)(HWND, LPCWSTR))GetProcAddress(huxtheme, "OpenThemeData");
4558 _GetThemeSysFont = (HRESULT (WINAPI *)(HTHEME, int, LOGFONTW *))GetProcAddress(huxtheme, "GetThemeSysFont"); 4565 _GetThemeSysFont = (HRESULT (WINAPI *)(HTHEME, int, LOGFONTW *))GetProcAddress(huxtheme, "GetThemeSysFont");
4566 _GetImmersiveColorFromColorSetEx = (DWORD (WINAPI *)(UINT, UINT, BOOL, UINT))GetProcAddress(huxtheme, MAKEINTRESOURCEA(95));
4567 _GetImmersiveColorTypeFromName = (int (WINAPI *)(const WCHAR *))GetProcAddress(huxtheme, MAKEINTRESOURCEA(96));
4568 _GetImmersiveUserColorSetPreference = (int (WINAPI *)(BOOL, BOOL))GetProcAddress(huxtheme, MAKEINTRESOURCEA(98));
4559 _BeginBufferedPaint = (HPAINTBUFFER (WINAPI *)(HDC, const RECT *, BP_BUFFERFORMAT, BP_PAINTPARAMS *, HDC *))GetProcAddress(huxtheme, "BeginBufferedPaint"); 4569 _BeginBufferedPaint = (HPAINTBUFFER (WINAPI *)(HDC, const RECT *, BP_BUFFERFORMAT, BP_PAINTPARAMS *, HDC *))GetProcAddress(huxtheme, "BeginBufferedPaint");
4560 _BufferedPaintSetAlpha = (HRESULT (WINAPI *)(HPAINTBUFFER, const RECT *, BYTE))GetProcAddress(huxtheme, "BufferedPaintSetAlpha"); 4570 _BufferedPaintSetAlpha = (HRESULT (WINAPI *)(HPAINTBUFFER, const RECT *, BYTE))GetProcAddress(huxtheme, "BufferedPaintSetAlpha");
4561 _DrawThemeTextEx = (HRESULT (WINAPI *)(HTHEME, HDC, int, int, LPCWSTR, int, DWORD, LPRECT, const DTTOPTS *))GetProcAddress(huxtheme, "DrawThemeTextEx"); 4571 _DrawThemeTextEx = (HRESULT (WINAPI *)(HTHEME, HDC, int, int, LPCWSTR, int, DWORD, LPRECT, const DTTOPTS *))GetProcAddress(huxtheme, "DrawThemeTextEx");
4562 _EndBufferedPaint = (HRESULT (WINAPI *)(HPAINTBUFFER, BOOL))GetProcAddress(huxtheme, "EndBufferedPaint"); 4572 _EndBufferedPaint = (HRESULT (WINAPI *)(HPAINTBUFFER, BOOL))GetProcAddress(huxtheme, "EndBufferedPaint");
4563 _CloseThemeData = (HRESULT (WINAPI *)(HTHEME))GetProcAddress(huxtheme, "CloseThemeData"); 4573 _CloseThemeData = (HRESULT (WINAPI *)(HTHEME))GetProcAddress(huxtheme, "CloseThemeData");