From: Feiyun Wang Date: Tue, 25 Jan 2022 02:17:30 +0000 (+0800) Subject: Fix panic "Unexpected DpiAwareness state" in Windows 10 for mingw32 version. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1cb0260b1c61a959d6ad4a0b9847aa58b59980b6;p=nethack Fix panic "Unexpected DpiAwareness state" in Windows 10 for mingw32 version. --- diff --git a/sys/windows/win10.c b/sys/windows/win10.c index 98bd5ae3c..6e610d4ea 100644 --- a/sys/windows/win10.c +++ b/sys/windows/win10.c @@ -9,6 +9,7 @@ #include "hack.h" typedef DPI_AWARENESS_CONTEXT(WINAPI *GetThreadDpiAwarenessContextProc)(VOID); +typedef DPI_AWARENESS_CONTEXT(WINAPI *SetThreadDpiAwarenessContextProc)(DPI_AWARENESS_CONTEXT); typedef BOOL(WINAPI *AreDpiAwarenessContextsEqualProc)( DPI_AWARENESS_CONTEXT dpiContextA, DPI_AWARENESS_CONTEXT dpiContextB); typedef UINT(WINAPI *GetDpiForWindowProc)(HWND hwnd); @@ -17,6 +18,7 @@ typedef LONG (WINAPI *GetCurrentPackageFullNameProc)(UINT32 *packageFullNameLeng typedef struct { BOOL Valid; + SetThreadDpiAwarenessContextProc SetThreadDpiAwarenessContext; GetThreadDpiAwarenessContextProc GetThreadDpiAwarenessContext; AreDpiAwarenessContextsEqualProc AreDpiAwarenessContextsEqual; GetDpiForWindowProc GetDpiForWindow; @@ -34,6 +36,10 @@ void win10_init(void) if (hUser32 == NULL) panic("Unable to load user32.dll"); + gWin10.SetThreadDpiAwarenessContext = (SetThreadDpiAwarenessContextProc) GetProcAddress(hUser32, "SetThreadDpiAwarenessContext"); + if (gWin10.SetThreadDpiAwarenessContext == NULL) + panic("Unable to get address of SetThreadDpiAwarenessContext()"); + gWin10.GetThreadDpiAwarenessContext = (GetThreadDpiAwarenessContextProc) GetProcAddress(hUser32, "GetThreadDpiAwarenessContext"); if (gWin10.GetThreadDpiAwarenessContext == NULL) panic("Unable to get address of GetThreadDpiAwarenessContext()"); @@ -63,6 +69,10 @@ void win10_init(void) } if (gWin10.Valid) { + if (!gWin10.SetThreadDpiAwarenessContext( + DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) + panic("Unable to set DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2"); + if (!gWin10.AreDpiAwarenessContextsEqual( gWin10.GetThreadDpiAwarenessContext(), DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2))