Hack to force redraw on some versions of Windows.

This commit is contained in:
casey langen 2023-01-01 17:30:12 -08:00
parent c0a2c437a7
commit be927af222

View File

@ -293,9 +293,19 @@ namespace cursespp {
if (dwmSetWindowAttribute) {
const auto settings = UISettings();
const auto foreground = settings.GetColorValue(UIColorType::Foreground);
BOOL isDarkMode = (((5 * foreground.G) + (2 * foreground.R) + foreground.B) > (8 * 128));
const BOOL isDarkMode = (((5 * foreground.G) + (2 * foreground.R) + foreground.B) > (8 * 128));
HWND mainHwnd = GetMainWindow();
dwmSetWindowAttribute(mainHwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &isDarkMode, sizeof(isDarkMode));
/* on some versions of Windows this doesn't redraw immediately; this hack very slightly resizes
the window to force a repaint... no amount of UpdateWindow/RedrawWindow/etc would do the trick */
RECT rect = { 0 };
GetWindowRect(mainWindow, &rect);
SetWindowPos(
mainWindow,
0,
rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top + 1,
SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
FreeLibrary(dwmapiDll);