From 83042a6d6864b44c9d15ed1c80c6d3121610f86a Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Thu, 27 Jan 2022 23:03:02 +0200 Subject: [PATCH] Fixes for weather panel, implemented icon-less modes, implemented dynamic size to fit contents --- CHANGELOG.md | 12 ++ ExplorerPatcher/GUI.c | 9 - ExplorerPatcher/dllmain.c | 323 ++++++++++++++++++++++-------- ExplorerPatcher/settings.reg | 12 +- ExplorerPatcher/utility.h | 10 + ep_weather_host/ep_weather.h | 2 + ep_weather_host/ep_weather_host.c | 18 +- ep_weather_host/ep_weather_host.h | 1 + version.h | 6 +- 9 files changed, 286 insertions(+), 107 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a98e94..2f7a723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,18 @@ Tested on OS build 22000.434. * Implemented Weather widget for the classic taskbar, similar to what is available in the more recent updates to Windows 10. Read more about it [here](https://github.com/valinet/ExplorerPatcher/wiki/Weather). +#### Feature enhancements + +* The weather widget recomputes its area automatically, by default, in order to fit its contents, instead of remaining at a fixed size; there is also an option to choose between the two behaviors (.1) +* Possibility to disable the icon in the weather widget (.1) + +#### Fixes + +* Fixed a bug that prevented the weather widget flyout from displaying correctly when the taskbar was using small icons (#741) (.1) +* Fixed inconsistencies when displaying the weather widget and the system themes are disabled (aka the classic theme is used) (.1) +* Screen readers now read the weather data when requested for the weather widget (.1) +* Changing the Start button style or weather widget layout does not toggle taskbar auto-hide now; instead, the settings take effect immediately (.1) + ## 22000.469.41 Tested on OS build 22000.434. diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index 8174c5e..24b3b59 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -92,15 +92,6 @@ LONG NTAPI OnVex(PEXCEPTION_POINTERS ExceptionInfo) return EXCEPTION_CONTINUE_SEARCH; } -BOOL IsHighContrast() -{ - HIGHCONTRASTW highContrast; - ZeroMemory(&highContrast, sizeof(HIGHCONTRASTW)); - highContrast.cbSize = sizeof(highContrast); - if (SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(highContrast), &highContrast, FALSE)) - return highContrast.dwFlags & HCF_HIGHCONTRASTON; - return FALSE; -} BOOL IsColorSchemeChangeMessage(LPARAM lParam) { BOOL is = FALSE; diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 7346e43..a9872fe 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -107,6 +107,7 @@ HANDLE hCanStartSws = NULL; DWORD dwWeatherViewMode = EP_WEATHER_VIEW_ICONTEXT; DWORD dwWeatherTemperatureUnit = EP_WEATHER_TUNIT_CELSIUS; DWORD dwWeatherUpdateSchedule = EP_WEATHER_UPDATE_NORMAL; +DWORD bWeatherFixedSize = FALSE; WCHAR* wszWeatherTerm = NULL; WCHAR* wszWeatherLanguage = NULL; WCHAR* wszEPWeatherKillswitch = NULL; @@ -3504,7 +3505,7 @@ LRESULT explorer_SendMessageW(HWND hWndx, UINT uMsg, WPARAM wParam, LPARAM lPara #pragma endregion -#pragma region "Set up taskbar button hooks" +#pragma region "Set up taskbar button hooks, implement Weather widget" #ifdef _WIN64 DWORD ShouldShowWidgetsInsteadOfCortana() @@ -3596,28 +3597,47 @@ BOOL explorer_DeleteMenu(HMENU hMenu, UINT uPosition, UINT uFlags) return DeleteMenu(hMenu, uPosition, uFlags); } +int prev_total_h = 0; SIZE (*PeopleButton_CalculateMinimumSizeFunc)(void*, SIZE*); SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) { SIZE ret = PeopleButton_CalculateMinimumSizeFunc(_this, pSz); - int mul = 1; if (epw) { - switch (dwWeatherViewMode) + if (bWeatherFixedSize) { - case EP_WEATHER_VIEW_ICONTEXT: - mul = 4; - break; - case EP_WEATHER_VIEW_ICONTEMP: - mul = 2; - break; - case EP_WEATHER_VIEW_ICONONLY: - mul = 1; - break; + int mul = 1; + switch (dwWeatherViewMode) + { + case EP_WEATHER_VIEW_ICONTEXT: + mul = 4; + break; + case EP_WEATHER_VIEW_TEXTONLY: + mul = 3; + break; + case EP_WEATHER_VIEW_ICONTEMP: + mul = 2; + break; + case EP_WEATHER_VIEW_ICONONLY: + case EP_WEATHER_VIEW_TEMPONLY: + mul = 1; + break; + } + pSz->cx = pSz->cx * mul; + } + else + { + if (!prev_total_h) + { + pSz->cx = 10000; + } + else + { + pSz->cx = prev_total_h; + } } } - //printf(">> %d %d\n", pSz->cx, pSz->cy); - pSz->cx = pSz->cx * mul; + //printf("[CalculateMinimumSize] %d %d\n", pSz->cx, pSz->cy); if (pSz->cy && epw) { BOOL bIsInitialized = TRUE; @@ -3629,7 +3649,9 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) { epw->lpVtbl->SetTerm(epw, MAX_PATH * sizeof(WCHAR), wszWeatherTerm); epw->lpVtbl->SetLanguage(epw, MAX_PATH * sizeof(WCHAR), wszWeatherLanguage); - if (FAILED(epw->lpVtbl->Initialize(epw, wszEPWeatherKillswitch, bAllocConsole, EP_WEATHER_PROVIDER_GOOGLE, rt, rt, dwWeatherTemperatureUnit, dwWeatherUpdateSchedule * 1000, pSz->cy / 48.0))) + UINT dpiX = 0, dpiY = 0; + HRESULT hr = GetDpiForMonitor(MonitorFromWindow(PeopleButton_LastHWND, MONITOR_DEFAULTTOPRIMARY), MDT_DEFAULT, &dpiX, &dpiY); + if (FAILED(epw->lpVtbl->Initialize(epw, wszEPWeatherKillswitch, bAllocConsole, EP_WEATHER_PROVIDER_GOOGLE, rt, rt, dwWeatherTemperatureUnit, dwWeatherUpdateSchedule * 1000, dpiX / 96.0))) { epw->lpVtbl->Release(epw); } @@ -3653,24 +3675,44 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) int PeopleBand_MulDivHook(int nNumber, int nNumerator, int nDenominator) { - //printf("<< %d %d %d\n", nNumber, nNumerator, nDenominator); - int mul = 1; + //printf("[MulDivHook] %d %d %d\n", nNumber, nNumerator, nDenominator); if (epw) { - switch (dwWeatherViewMode) + if (bWeatherFixedSize) { - case EP_WEATHER_VIEW_ICONTEXT: - mul = 4; - break; - case EP_WEATHER_VIEW_ICONTEMP: - mul = 2; - break; - case EP_WEATHER_VIEW_ICONONLY: - mul = 1; - break; + int mul = 1; + switch (dwWeatherViewMode) + { + case EP_WEATHER_VIEW_ICONTEXT: + mul = 4; + break; + case EP_WEATHER_VIEW_TEXTONLY: + mul = 3; + break; + case EP_WEATHER_VIEW_ICONTEMP: + mul = 2; + break; + case EP_WEATHER_VIEW_ICONONLY: + case EP_WEATHER_VIEW_TEMPONLY: + mul = 1; + break; + } + return MulDiv(nNumber * mul, nNumerator, nDenominator); + } + else + { + if (prev_total_h) + { + return prev_total_h; + } + else + { + prev_total_h = MulDiv(nNumber, nNumerator, nDenominator); + return prev_total_h; + } } } - return MulDiv(nNumber * mul, nNumerator, nDenominator); + return MulDiv(nNumber, nNumerator, nDenominator); } DWORD epw_cbTemperature = 0; @@ -3711,6 +3753,11 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( if (a5 == 0x21 && epw) { BOOL bUseCachedData = InSendMessage(); + BOOL bIsThemeActive = TRUE; + if (!IsThemeActive() || IsHighContrast()) + { + bIsThemeActive = FALSE; + } HRESULT hr = S_OK; if (bUseCachedData ? TRUE : SUCCEEDED(hr = epw->lpVtbl->LockData(epw))) { @@ -3775,6 +3822,13 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( { if (!bUseCachedData) { + WCHAR wszBuffer[MAX_PATH]; + ZeroMemory(wszBuffer, sizeof(WCHAR) * MAX_PATH); + swprintf_s(wszBuffer, MAX_PATH, L"%s %s, %s, ", epw_wszTemperature, epw_wszUnit, epw_wszCondition); + int len = wcslen(wszBuffer); + epw->lpVtbl->GetTitle(epw, sizeof(WCHAR) * (MAX_PATH - len), wszBuffer + len, dwWeatherViewMode); + SetWindowTextW(PeopleButton_LastHWND, wszBuffer); + epw->lpVtbl->UnlockData(epw); bShouldUnlockData = FALSE; } @@ -3784,9 +3838,9 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( NONCLIENTMETRICS ncm; ZeroMemory(&ncm, sizeof(NONCLIENTMETRICS)); ncm.cbSize = sizeof(NONCLIENTMETRICS); - SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0); + SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpiX); logFont = ncm.lfCaptionFont; - logFont.lfHeight = -14 * (dpiX / 96.0); + logFont.lfWeight = FW_NORMAL; if (bEmptyData) { DWORD dwVal = 1, dwSize = sizeof(DWORD); @@ -3810,9 +3864,16 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( if (hDC) { COLORREF rgbColor = RGB(0, 0, 0); - if (ShouldSystemUseDarkMode && ShouldSystemUseDarkMode()) + if (bIsThemeActive) { - rgbColor = RGB(255, 255, 255); + if (ShouldSystemUseDarkMode && ShouldSystemUseDarkMode()) + { + rgbColor = RGB(255, 255, 255); + } + } + else + { + rgbColor = GetSysColor(COLOR_WINDOWTEXT); } HFONT hOldFont = SelectFont(hDC, hFont); if (bEmptyData) @@ -3846,19 +3907,22 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( DWORD dwTextFlags = DT_SINGLELINE | DT_VCENTER | DT_HIDEPREFIX; WCHAR wszText1[MAX_PATH]; - swprintf_s(wszText1, MAX_PATH, L"%s %s", epw_wszTemperature, dwWeatherTemperatureUnit == EP_WEATHER_TUNIT_FAHRENHEIT ? L"\u00B0F" : L"\u00B0C");// epw_wszUnit); + swprintf_s(wszText1, MAX_PATH, L"%s%s %s", bIsThemeActive ? L"" : L" ", epw_wszTemperature, dwWeatherTemperatureUnit == EP_WEATHER_TUNIT_FAHRENHEIT ? L"\u00B0F" : L"\u00B0C");// epw_wszUnit); RECT rcText1; SetRect(&rcText1, 0, 0, a4->right, a4->bottom); DrawTextW(hDC, wszText1, -1, &rcText1, dwTextFlags | DT_CALCRECT); rcText1.bottom = a4->bottom; WCHAR wszText2[MAX_PATH]; - swprintf_s(wszText2, MAX_PATH, L"%s", epw_wszCondition); + swprintf_s(wszText2, MAX_PATH, L"%s%s", bIsThemeActive ? L"" : L" ", epw_wszCondition); RECT rcText2; SetRect(&rcText2, 0, 0, a4->right, a4->bottom); DrawTextW(hDC, wszText2, -1, &rcText2, dwTextFlags | DT_CALCRECT); rcText2.bottom = a4->bottom; - dwTextFlags |= DT_END_ELLIPSIS; + if (bWeatherFixedSize) + { + dwTextFlags |= DT_END_ELLIPSIS; + } int addend = 0; //int rt = MulDiv(48, a4->bottom, 60); @@ -3866,12 +3930,18 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( int p = 0;// MulDiv(rt, 4, 64); int margin_h = MulDiv(12, dpiX, 144); + BOOL bIsIconMode = ( + dwWeatherViewMode == EP_WEATHER_VIEW_ICONTEMP || + dwWeatherViewMode == EP_WEATHER_VIEW_ICONTEXT || + dwWeatherViewMode == EP_WEATHER_VIEW_ICONONLY); switch (dwWeatherViewMode) { case EP_WEATHER_VIEW_ICONTEXT: + case EP_WEATHER_VIEW_TEXTONLY: addend = (rcText1.right - rcText1.left) + margin_h + (rcText2.right - rcText2.left) + margin_h; break; case EP_WEATHER_VIEW_ICONTEMP: + case EP_WEATHER_VIEW_TEMPONLY: addend = (rcText1.right - rcText1.left) + margin_h; break; case EP_WEATHER_VIEW_ICONONLY: @@ -3879,58 +3949,73 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( break; } int margin_v = (a4->bottom - rt) / 2; - int total_h = (margin_h - p) + rt + (margin_h - p) + addend; - if (total_h > a4->right) + int total_h = (bIsIconMode ? ((margin_h - p) + rt + (margin_h - p)) : margin_h) + addend; + if (bWeatherFixedSize) { - int diff = total_h - a4->right; - rcText2.right -= diff - 2; - switch (dwWeatherViewMode) + if (total_h > a4->right) { - case EP_WEATHER_VIEW_ICONTEXT: - addend = (rcText1.right - rcText1.left) + margin_h + (rcText2.right - rcText2.left) + margin_h; - break; - case EP_WEATHER_VIEW_ICONTEMP: - addend = (rcText1.right - rcText1.left) + margin_h; - break; - case EP_WEATHER_VIEW_ICONONLY: - addend = 0; - break; + int diff = total_h - a4->right; + rcText2.right -= diff - 2; + switch (dwWeatherViewMode) + { + case EP_WEATHER_VIEW_ICONTEXT: + case EP_WEATHER_VIEW_TEXTONLY: + addend = (rcText1.right - rcText1.left) + margin_h + (rcText2.right - rcText2.left) + margin_h; + break; + case EP_WEATHER_VIEW_ICONTEMP: + case EP_WEATHER_VIEW_TEMPONLY: // should be impossible + addend = (rcText1.right - rcText1.left) + margin_h; + break; + case EP_WEATHER_VIEW_ICONONLY: + addend = 0; + break; + } + total_h = (margin_h - p) + rt + (margin_h - p) + addend; } - total_h = (margin_h - p) + rt + (margin_h - p) + addend; } - - int start_x = (a4->right - total_h) / 2; + int start_x = 0; // prev_total_h - total_h; + if (bWeatherFixedSize) + { + start_x = (a4->right - total_h) / 2; + } HBITMAP hBitmap = NULL, hOldBitmap = NULL; void* pvBits = NULL; SIZE size; - BITMAPINFOHEADER BMIH; - ZeroMemory(&BMIH, sizeof(BITMAPINFOHEADER)); - BMIH.biSize = sizeof(BITMAPINFOHEADER); - BMIH.biWidth = rt; - BMIH.biHeight = -rt; - BMIH.biPlanes = 1; - BMIH.biBitCount = 32; - BMIH.biCompression = BI_RGB; - hBitmap = CreateDIBSection(hDC, &BMIH, 0, &pvBits, NULL, 0); - if (hBitmap) + if (bIsIconMode) { - memcpy(pvBits, epw_pImage, epw_cbImage); - hOldBitmap = SelectBitmap(hDC, hBitmap); + BITMAPINFOHEADER BMIH; + ZeroMemory(&BMIH, sizeof(BITMAPINFOHEADER)); + BMIH.biSize = sizeof(BITMAPINFOHEADER); + BMIH.biWidth = rt; + BMIH.biHeight = -rt; + BMIH.biPlanes = 1; + BMIH.biBitCount = 32; + BMIH.biCompression = BI_RGB; + hBitmap = CreateDIBSection(hDC, &BMIH, 0, &pvBits, NULL, 0); + if (hBitmap) + { + memcpy(pvBits, epw_pImage, epw_cbImage); + hOldBitmap = SelectBitmap(hDC, hBitmap); - BLENDFUNCTION bf; - bf.BlendOp = AC_SRC_OVER; - bf.BlendFlags = 0; - bf.SourceConstantAlpha = 0xFF; - bf.AlphaFormat = AC_SRC_ALPHA; - GdiAlphaBlend(hdc, start_x + (margin_h - p), margin_v, rt, rt, hDC, 0, 0, rt, rt, bf); + BLENDFUNCTION bf; + bf.BlendOp = AC_SRC_OVER; + bf.BlendFlags = 0; + bf.SourceConstantAlpha = 0xFF; + bf.AlphaFormat = AC_SRC_ALPHA; + GdiAlphaBlend(hdc, start_x + (margin_h - p), margin_v, rt, rt, hDC, 0, 0, rt, rt, bf); - SelectBitmap(hDC, hOldBitmap); - DeleteBitmap(hBitmap); + SelectBitmap(hDC, hOldBitmap); + DeleteBitmap(hBitmap); + } } - if (dwWeatherViewMode == EP_WEATHER_VIEW_ICONTEMP || dwWeatherViewMode == EP_WEATHER_VIEW_ICONTEXT) + if (dwWeatherViewMode == EP_WEATHER_VIEW_ICONTEMP || + dwWeatherViewMode == EP_WEATHER_VIEW_ICONTEXT || + dwWeatherViewMode == EP_WEATHER_VIEW_TEMPONLY || + dwWeatherViewMode == EP_WEATHER_VIEW_TEXTONLY + ) { size.cx = rcText1.right - rcText1.left; size.cy = rcText1.bottom - rcText1.top; @@ -3946,14 +4031,16 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( bf.BlendFlags = 0; bf.SourceConstantAlpha = 0xFF; bf.AlphaFormat = AC_SRC_ALPHA; - GdiAlphaBlend(hdc, start_x + (margin_h - p) + rt + (margin_h - p), 0, BMInf.bmWidth, BMInf.bmHeight, hDC, 0, 0, BMInf.bmWidth, BMInf.bmHeight, bf); + GdiAlphaBlend(hdc, start_x + (bIsIconMode ? ((margin_h - p) + rt + (margin_h - p)) : margin_h), 0, BMInf.bmWidth, BMInf.bmHeight, hDC, 0, 0, BMInf.bmWidth, BMInf.bmHeight, bf); SelectBitmap(hDC, hOldBMP); DeleteBitmap(hBitmap); } } - if (dwWeatherViewMode == EP_WEATHER_VIEW_ICONTEXT) + if (dwWeatherViewMode == EP_WEATHER_VIEW_ICONTEXT || + dwWeatherViewMode == EP_WEATHER_VIEW_TEXTONLY + ) { size.cx = rcText2.right - rcText2.left; size.cy = rcText2.bottom - rcText2.top; @@ -3969,12 +4056,46 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( bf.BlendFlags = 0; bf.SourceConstantAlpha = 0xFF; bf.AlphaFormat = AC_SRC_ALPHA; - GdiAlphaBlend(hdc, start_x + (margin_h - p) + rt + (margin_h - p) + (rcText1.right - rcText1.left) + margin_h, 0, BMInf.bmWidth, BMInf.bmHeight, hDC, 0, 0, BMInf.bmWidth, BMInf.bmHeight, bf); + GdiAlphaBlend(hdc, start_x + (bIsIconMode ? ((margin_h - p) + rt + (margin_h - p)) : margin_h) + (rcText1.right - rcText1.left) + margin_h, 0, BMInf.bmWidth, BMInf.bmHeight, hDC, 0, 0, BMInf.bmWidth, BMInf.bmHeight, bf); SelectBitmap(hDC, hOldBMP); DeleteBitmap(hBitmap); } } + + if (bWeatherFixedSize) + { + + } + else + { + if (total_h != prev_total_h) + { + prev_total_h = total_h; + SendNotifyMessageW(HWND_BROADCAST, WM_WININICHANGE, 0, (LPARAM)L"TraySettings"); + } + } + + /* + SetLastError(0); + LONG_PTR oldStyle = GetWindowLongPtrW(PeopleButton_LastHWND, GWL_EXSTYLE); + if (!GetLastError()) + { + LONG_PTR style; + if (bIsThemeActive) + { + style = oldStyle & ~WS_EX_DLGMODALFRAME; + } + else + { + style = oldStyle | WS_EX_DLGMODALFRAME; + } + if (style != oldStyle) + { + SetWindowLongPtrW(PeopleButton_LastHWND, GWL_EXSTYLE, style); + } + } + */ } SelectFont(hDC, hOldFont); DeleteDC(hDC); @@ -4267,6 +4388,15 @@ BOOL explorer_SetChildWindowNoActivateHook(HWND hWnd) if (SUCCEEDED(CoCreateInstance(&CLSID_EPWeather, NULL, CLSCTX_LOCAL_SERVER, &IID_IEPWeather, &epw)) && epw) { epw->lpVtbl->SetNotifyWindow(epw, hWnd); + + WCHAR wszBuffer[MAX_PATH]; + ZeroMemory(wszBuffer, sizeof(WCHAR) * MAX_PATH); + HMODULE hModule = GetModuleHandleW(L"pnidui.dll"); + if (hModule) + { + LoadStringW(hModule, 35, wszBuffer, MAX_PATH); + } + SetWindowTextW(hWnd, wszBuffer); } } } @@ -4695,9 +4825,10 @@ DWORD WindowSwitcher(DWORD unused) #pragma region "Load Settings from registry" -#define REFRESHUI_NONE 0b00 -#define REFRESHUI_GLOM 0b01 -#define REFRESHUI_ORB 0b10 +#define REFRESHUI_NONE 0b000 +#define REFRESHUI_GLOM 0b001 +#define REFRESHUI_ORB 0b010 +#define REFRESHUI_PEOPLE 0b100 void WINAPI LoadSettings(LPARAM lParam) { BOOL bIsExplorer = LOWORD(lParam); @@ -5268,9 +5399,7 @@ void WINAPI LoadSettings(LPARAM lParam) ); if (dwWeatherViewMode != dwOldWeatherViewMode && PeopleButton_LastHWND) { - ToggleTaskbarAutohide(); - ToggleTaskbarAutohide(); - InvalidateRect(PeopleButton_LastHWND, NULL, TRUE); + dwRefreshUIMask |= REFRESHUI_PEOPLE; } DWORD dwOldUpdateSchedule = dwWeatherUpdateSchedule; @@ -5311,6 +5440,7 @@ void WINAPI LoadSettings(LPARAM lParam) { epw->lpVtbl->SetTerm(epw, MAX_PATH * sizeof(WCHAR), wszWeatherTerm); } + dwSize = MAX_PATH * sizeof(WCHAR); if (RegQueryValueExW( hKey, @@ -5334,6 +5464,21 @@ void WINAPI LoadSettings(LPARAM lParam) { epw->lpVtbl->SetLanguage(epw, MAX_PATH * sizeof(WCHAR), wszWeatherLanguage); } + + DWORD bOldWeatherFixedSize = bWeatherFixedSize; + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("WeatherFixedSize"), + 0, + NULL, + &bWeatherFixedSize, + &dwSize + ); + if (bWeatherFixedSize != bOldWeatherFixedSize && epw) + { + dwRefreshUIMask |= REFRESHUI_PEOPLE; + } #endif dwTemp = TASKBARGLOMLEVEL_DEFAULT; @@ -5563,13 +5708,19 @@ void WINAPI LoadSettings(LPARAM lParam) { Explorer_RefreshUI(0); } - if (dwRefreshUIMask & REFRESHUI_ORB) + if ((dwRefreshUIMask & REFRESHUI_ORB) || (dwRefreshUIMask & REFRESHUI_PEOPLE)) { + SendNotifyMessageW(HWND_BROADCAST, WM_WININICHANGE, 0, (LPARAM)L"TraySettings"); + if (dwRefreshUIMask & REFRESHUI_ORB) + { + InvalidateRect(FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL), NULL, FALSE); + } + if (dwRefreshUIMask & REFRESHUI_PEOPLE) + { #ifdef _WIN64 - ToggleTaskbarAutohide(); - ToggleTaskbarAutohide(); + InvalidateRect(PeopleButton_LastHWND, NULL, TRUE); #endif - InvalidateRect(FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL), NULL, FALSE); + } } } } diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 5dea111..1af04cd 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -350,11 +350,17 @@ [HKEY_CURRENT_USER\Software\ExplorerPatcher] ;b Show Weather on the taskbar ;"Virtualized_{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}_PeopleBand"=dword:00000000 -;c 3 Layout -;x 1 Icon only +;c 5 Layout +;x 0 Icon and description (default) ;x 3 Icon and temperature -;x 0 Icon and text (default) +;x 1 Icon only +;x 4 Temperature only +;x 5 Temperature and description "WeatherViewMode"=dword:00000000 +;c 2 Widget size +;x 0 Enlarge/shrink to fit contents (default) +;x 1 Fixed +"WeatherFixedSize"=dword:00000000 ;c 7 Update frequency ;x 60 Every minute ;x 300 Every 5 minutes diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index 5986d75..57f42d0 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -245,6 +245,16 @@ WCHAR* StrReplaceAllW(const WCHAR* s, const WCHAR* oldW, const WCHAR* newW, int* HRESULT InputBox(BOOL bPassword, HWND hWnd, LPCWSTR wszPrompt, LPCWSTR wszTitle, LPCWSTR wszDefault, LPCWSTR wszAnswer, DWORD cbAnswer); +inline BOOL IsHighContrast() +{ + HIGHCONTRASTW highContrast; + ZeroMemory(&highContrast, sizeof(HIGHCONTRASTW)); + highContrast.cbSize = sizeof(highContrast); + if (SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(highContrast), &highContrast, FALSE)) + return highContrast.dwFlags & HCF_HIGHCONTRASTON; + return FALSE; +} + // https://codereview.stackexchange.com/questions/29198/random-string-generator-in-c static inline WCHAR* rand_string(WCHAR* str, size_t size) { diff --git a/ep_weather_host/ep_weather.h b/ep_weather_host/ep_weather.h index 674ea32..81d0ab9 100644 --- a/ep_weather_host/ep_weather.h +++ b/ep_weather_host/ep_weather.h @@ -43,6 +43,8 @@ DEFINE_GUID(IID_IEPWeather, #define EP_WEATHER_VIEW_ICONONLY 1 #define EP_WEATHER_VIEW_ICONTEMP 3 #define EP_WEATHER_VIEW_ICONTEXT 0 +#define EP_WEATHER_VIEW_TEMPONLY 4 +#define EP_WEATHER_VIEW_TEXTONLY 5 #define EP_WEATHER_UPDATE_NORMAL 1200 #define EP_WEATHER_UPDATE_REDUCED 3600 diff --git a/ep_weather_host/ep_weather_host.c b/ep_weather_host/ep_weather_host.c index e344355..27ce1f8 100644 --- a/ep_weather_host/ep_weather_host.c +++ b/ep_weather_host/ep_weather_host.c @@ -588,6 +588,7 @@ LRESULT CALLBACK epw_Weather_WindowProc(_In_ HWND hWnd, _In_ UINT uMsg, _In_ WPA DWORD WINAPI epw_Weather_MainThread(EPWeather* _this) { HRESULT hr = S_OK; + DWORD bIsThemeActive = IsThemeActive(); SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); @@ -614,7 +615,7 @@ DWORD WINAPI epw_Weather_MainThread(EPWeather* _this) wc.style = CS_DBLCLKS; wc.lpfnWndProc = epw_Weather_WindowProc; wc.hInstance = epw_hModule; - wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + wc.hbrBackground = bIsThemeActive ? (HBRUSH)GetStockObject(BLACK_BRUSH) : (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszClassName = _T(EPW_WEATHER_CLASSNAME); wc.hCursor = LoadCursorW(NULL, IDC_ARROW); if (!RegisterClassW(&wc)) @@ -623,7 +624,7 @@ DWORD WINAPI epw_Weather_MainThread(EPWeather* _this) goto cleanup; } - _this->hWnd = CreateWindowExW(0, _T(EPW_WEATHER_CLASSNAME), L"", WS_OVERLAPPED | WS_CAPTION, 100, 100, 825 * _this->dpi, 515 * _this->dpi, NULL, NULL, epw_hModule, _this); // 1030, 630 + _this->hWnd = CreateWindowExW(0, _T(EPW_WEATHER_CLASSNAME), L"", WS_OVERLAPPED | WS_CAPTION, 100, 100, 690 * _this->dpi, 425 * _this->dpi, NULL, NULL, epw_hModule, _this); // 1030, 630 if (!_this->hWnd) { _this->hrLastError = HRESULT_FROM_WIN32(GetLastError()); @@ -649,10 +650,13 @@ DWORD WINAPI epw_Weather_MainThread(EPWeather* _this) goto cleanup; } - MARGINS marGlassInset = { -1, -1, -1, -1 }; // -1 means the whole window - DwmExtendFrameIntoClientArea(_this->hWnd, &marGlassInset); - BOOL value = 1; - DwmSetWindowAttribute(_this->hWnd, 1029, &value, sizeof(BOOL)); + if (bIsThemeActive) + { + MARGINS marGlassInset = { -1, -1, -1, -1 }; // -1 means the whole window + DwmExtendFrameIntoClientArea(_this->hWnd, &marGlassInset); + BOOL value = 1; + DwmSetWindowAttribute(_this->hWnd, 1029, &value, sizeof(BOOL)); + } InterlockedExchange64(&_this->bBrowserBusy, TRUE); @@ -942,9 +946,11 @@ HRESULT STDMETHODCALLTYPE epw_Weather_GetTitle(EPWeather* _this, DWORD cbTitle, switch (dwType) { case EP_WEATHER_VIEW_ICONTEXT: + case EP_WEATHER_VIEW_TEXTONLY: swprintf_s(wszBuffer, MAX_PATH, L"%s", _this->wszLocation); break; case EP_WEATHER_VIEW_ICONTEMP: + case EP_WEATHER_VIEW_TEMPONLY: swprintf_s(wszBuffer, MAX_PATH, L"%s - %s", _this->wszLocation, _this->wszCondition); break; case EP_WEATHER_VIEW_ICONONLY: diff --git a/ep_weather_host/ep_weather_host.h b/ep_weather_host/ep_weather_host.h index 29b65de..cb54abb 100644 --- a/ep_weather_host/ep_weather_host.h +++ b/ep_weather_host/ep_weather_host.h @@ -12,6 +12,7 @@ #include #pragma comment(lib, "IPHLPAPI.lib") #include "WebView2.h" +#pragma comment(lib, "uxtheme.lib") DEFINE_GUID(IID_ITaskbarList, 0x56FDF342, 0xFD6D, 0x11d0, 0x95, 0x8A, 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90); diff --git a/version.h b/version.h index adc681c..66a0050 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define VER_MAJOR 22000 #define VER_MINOR 469 #define VER_BUILD_HI 42 -#define VER_BUILD_LO 0 +#define VER_BUILD_LO 1 #define VER_FLAGS VS_FF_PRERELEASE @@ -12,5 +12,5 @@ #define VER_STR(arg) #arg // The String form of the version numbers -#define VER_FILE_STRING VALUE "FileVersion", "22000.469.42.0" -#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.469.42.0" +#define VER_FILE_STRING VALUE "FileVersion", "22000.469.42.1" +#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.469.42.1"