From 3c0a5e4c4c30157dc7056803886c59a13a2357c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 12 Jan 2023 01:01:03 +0100 Subject: [PATCH] Fix the white line --- Windows/MainWindow.cpp | 55 ++++++++++++++++++++++++++++++++-- Windows/W32Util/DarkMode.cpp | 4 ++- Windows/W32Util/DarkMode.h | 1 + Windows/W32Util/UAHMenuBar.cpp | 1 - 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index a68d24e2b0..7bb751f0fb 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -179,7 +179,7 @@ namespace MainWindow WNDCLASSEX wcdisp; memset(&wcdisp, 0, sizeof(wcdisp)); - // Display Window + // Display Window (contained in main window) wcdisp.cbSize = sizeof(WNDCLASSEX); wcdisp.style = CS_HREDRAW | CS_VREDRAW; wcdisp.lpfnWndProc = (WNDPROC)DisplayProc; @@ -730,6 +730,37 @@ namespace MainWindow return 0; } + RECT MapRectFromClientToWndCoords(HWND hwnd, const RECT & r) + { + RECT wnd_coords = r; + + // map to screen + MapWindowPoints(hwnd, NULL, reinterpret_cast(&wnd_coords), 2); + + RECT scr_coords; + GetWindowRect(hwnd, &scr_coords); + + // map to window coords by substracting the window coord origin in + // screen coords. + OffsetRect(&wnd_coords, -scr_coords.left, -scr_coords.top); + + return wnd_coords; + } + + RECT GetNonclientMenuBorderRect(HWND hwnd) + { + RECT r; + GetClientRect(hwnd, &r); + r = MapRectFromClientToWndCoords(hwnd, r); + int y = r.top - 1; + return { + r.left, + y, + r.right, + y + 1 + }; + } + LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT darkResult = 0; if (UAHDarkModeWndProc(hWnd, message, wParam, lParam, &darkResult)) { @@ -759,6 +790,26 @@ namespace MainWindow } break; + // Hack to kill the white line underneath the menubar. + // From https://stackoverflow.com/questions/57177310/how-to-paint-over-white-line-between-menu-bar-and-client-area-of-window + case WM_NCPAINT: + case WM_NCACTIVATE: + { + if (!IsDarkModeEnabled() || IsIconic(hWnd)) { + return DefWindowProc(hWnd, message, wParam, lParam); + } + + auto result = DefWindowProc(hWnd, message, wParam, lParam); + // Paint over the line with pure black. Could also try to figure out the dark theme color. + HDC hdc = GetWindowDC(hWnd); + RECT r = GetNonclientMenuBorderRect(hWnd); + HBRUSH red = CreateSolidBrush(RGB(0, 0, 0)); + FillRect(hdc, &r, red); + DeleteObject(red); + ReleaseDC(hWnd, hdc); + return result; + } + case WM_GETMINMAXINFO: { MINMAXINFO *minmax = reinterpret_cast(lParam); @@ -814,7 +865,7 @@ namespace MainWindow case WM_ERASEBKGND: // This window is always covered by DisplayWindow. No reason to erase. - return 1; + return 0; case WM_MOVE: SavePosition(); diff --git a/Windows/W32Util/DarkMode.cpp b/Windows/W32Util/DarkMode.cpp index efd38829b8..34c71d54f2 100644 --- a/Windows/W32Util/DarkMode.cpp +++ b/Windows/W32Util/DarkMode.cpp @@ -158,6 +158,9 @@ LRESULT DarkModeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { return FALSE; } +bool IsDarkModeEnabled() { + return g_darkModeEnabled; +} constexpr bool CheckBuildNumber(DWORD buildNumber) { @@ -182,7 +185,6 @@ void InitDarkMode() HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); if (hUxtheme) { - _OpenNcThemeData = reinterpret_cast(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(49))); _RefreshImmersiveColorPolicyState = reinterpret_cast(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(104))); _GetIsImmersiveColorUsingHighContrast = reinterpret_cast(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(106))); diff --git a/Windows/W32Util/DarkMode.h b/Windows/W32Util/DarkMode.h index 76288e0495..50ac9498db 100644 --- a/Windows/W32Util/DarkMode.h +++ b/Windows/W32Util/DarkMode.h @@ -104,6 +104,7 @@ void InitDarkMode(); bool AllowDarkModeForWindow(HWND hWnd, bool allow); void RefreshTitleBarThemeColor(HWND hWnd); bool IsColorSchemeChangeMessage(LPARAM lParam); +bool IsDarkModeEnabled(); void DarkModeInitDialog(HWND hDlg); LRESULT DarkModeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); diff --git a/Windows/W32Util/UAHMenuBar.cpp b/Windows/W32Util/UAHMenuBar.cpp index 53c87b863b..32f9003585 100644 --- a/Windows/W32Util/UAHMenuBar.cpp +++ b/Windows/W32Util/UAHMenuBar.cpp @@ -38,7 +38,6 @@ bool UAHDarkModeWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, L } DrawThemeBackground(g_menuTheme, pUDM->hdc, MENU_POPUPITEM, MPI_NORMAL, &rc, nullptr); - return true; } case WM_UAHDRAWMENUITEM: