From e7acb51773062978af8e4d4486add0ef878453c5 Mon Sep 17 00:00:00 2001 From: Zarg <62082797+Zaarrg@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:17:18 +0100 Subject: [PATCH] Blurry text fix - Blurry text fix - we are no DPI aware :) --- src/main.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 7c32b26..750f352 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,10 @@ #include #pragma comment(lib, "gdiplus.lib") +//dpi +#include +#include +#pragma comment(lib, "Shcore.lib") // WebView2 #include "WebView2.h" @@ -2434,6 +2438,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; } + case WM_DPICHANGED: { + // Obtain the new suggested window rect from lParam + RECT* const newRect = reinterpret_cast(lParam); + SetWindowPos(hWnd, NULL, newRect->left, newRect->top, + newRect->right - newRect->left, newRect->bottom - newRect->top, + SWP_NOZORDER | SWP_NOACTIVATE); + break; + } + case WM_NOTIFY_UPDATE: { if (!g_pendingUpdateMsg.is_null()) { SendToJS(g_pendingUpdateMsg); @@ -2640,6 +2653,20 @@ int main(int argc, char* argv[]) SetUnhandledExceptionFilter(ExceptionFilter); atexit(Cleanup); + if (IsWindowsVersionOrGreater(10, 0, 14393)) { + // Windows 10 Anniversary Update (1607) or later + // Dynamically get the function pointer to ensure compatibility + typedef BOOL(WINAPI *SetProcessDpiAwarenessContextFunc)(DPI_AWARENESS_CONTEXT); + auto setDpiAwarenessContext = reinterpret_cast( + GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetProcessDpiAwarenessContext")); + if (setDpiAwarenessContext) { + setDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + } + } else { + // Fallback for Windows 8.1 and Windows 10 before 1607: + SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); + } + // Parse command-line arguments ParseCommandLineArgs(argc, argv);