From 9b5919ab22eb523246563b4ff6d9b91ad46c3e45 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Thu, 28 Oct 2021 11:12:07 +0200 Subject: [PATCH] Fixed DPI Scaling problems #616 --- neo/sys/win32/win_main.cpp | 44 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index 3e69ed60..9c14a430 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -86,11 +86,48 @@ void Sys_GetExeLaunchMemoryStatus( sysMemoryStats_t& stats ) /* ================== -Sys_Sentry +Sys_SetDPIAwareness #616 + +Code that tells windows we're High DPI aware so it doesn't scale our windows. +Taken from Yamagi Quake II ================== */ -void Sys_Sentry() +typedef enum D3_PROCESS_DPI_AWARENESS { + D3_PROCESS_DPI_UNAWARE = 0, + D3_PROCESS_SYSTEM_DPI_AWARE = 1, + D3_PROCESS_PER_MONITOR_DPI_AWARE = 2 +} YQ2_PROCESS_DPI_AWARENESS; + +void Sys_SetDPIAwareness() +{ + // For Vista, Win7 and Win8 + BOOL( WINAPI * SetProcessDPIAware )( void ) = NULL; + + /* Win8.1 and later */ + HRESULT( WINAPI * SetProcessDpiAwareness )( D3_PROCESS_DPI_AWARENESS dpiAwareness ) = NULL; + + + HINSTANCE userDLL = LoadLibrary( "USER32.DLL" ); + if( userDLL ) + { + SetProcessDPIAware = ( BOOL( WINAPI* )( void ) ) GetProcAddress( userDLL, "SetProcessDPIAware" ); + } + + HINSTANCE shcoreDLL = LoadLibrary( "SHCORE.DLL" ); + if( shcoreDLL ) + { + SetProcessDpiAwareness = ( HRESULT( WINAPI* )( YQ2_PROCESS_DPI_AWARENESS ) ) GetProcAddress( shcoreDLL, "SetProcessDpiAwareness" ); + } + + if( SetProcessDpiAwareness ) + { + SetProcessDpiAwareness( D3_PROCESS_PER_MONITOR_DPI_AWARE ); + } + else if( SetProcessDPIAware ) + { + SetProcessDPIAware(); + } } @@ -1908,6 +1945,9 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin Sys_GetCurrentMemoryStatus( exeLaunchMemoryStats ); + // DG: tell Windows 8+ we're high dpi aware, otherwise display scaling screws up the game + Sys_SetDPIAwareness(); + #if 0 DWORD handler = ( DWORD )_except_handler; __asm