Skip to content

Commit

Permalink
Fixed DPI Scaling problems #616
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeckebans committed Oct 28, 2021
1 parent 41e3542 commit 9b5919a
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions neo/sys/win32/win_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9b5919a

Please sign in to comment.