Introduction
Adapting the DPI (dots per inch) of applications on Windows has been a frustrating experience for many users. The issue comes to a head when the DPI setting of the display is higher than the default system DPI, leading to a "jumpscale" effect where application windows jump over the monitor border by 50%. This can cause issues with visibility and using the application, making it seem like a nightmare compared to macOS.
The Problem with System DPI vs Specific Applications DPI
The problem with Windows DPI scaling is that it works at a system level. This means that it applies to all applications, regardless of their individual DPI requirements. This can cause a number of problems, including:
- Applications appearing too small or too large
- Text becoming illegible
- Inconsistent interface scaling across different applications
Forcing Specific Applications to Increase DPI
To get around these issues, you can force specific applications to increase their DPI setting. This can be done using the following steps:
- Right-click on the application's shortcut and select 'Properties'.
- In the 'Properties' window, select the 'Compatibility' tab.
- Check the box next to 'Override high DPI scaling behavior'.
- Select 'System (Enhanced)' from the drop-down menu.
- Click 'Apply' and then 'OK'.
// Example code block for increasing DPI setting in a specific application
using System;
using System.IO;
using System.Runtime.InteropServices;
class Program
{
static void Main()
{
// Set the DPI setting for the application
int dpiX = 144;
int dpiY = 144;
SetProcessDpiAwareness(PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE);
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
int logPixelsX = GetDeviceCaps(GetDC(IntPtr.Zero), LOGPIXELSX);
int logPixelsY = GetDeviceCaps(GetDC(IntPtr.Zero), LOGPIXELSY);
double scaleX = (double)dpiX / (double)logPixelsX;
double scaleY = (double)dpiY / (double)logPixelsY;
float scale = (float)Math.Sqrt(scaleX * scaleY);
int newLogPixelsX = (int)(dpiX / scale);
int newLogPixelsY = (int)(dpiY / scale);
ChangeDpi(GetDC(IntPtr.Zero), newLogPixelsX, newLogPixelsY);
}
[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
[DllImport("user32.dll")]
static extern bool SetProcessDpiAwareness(PROCESS_DPI_AWARENESS awareness);
[DllImport("shcore.dll")]
static extern int SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT context);
[DllImport("user32.dll")]
static extern bool SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT context);
[DllImport("gdi32.dll")]
static extern bool ChangeDpi(IntPtr hdc, int dpiX, int dpiY);
}
public enum PROCESS_DPI_AWARENESS
{
PROCESS_DPI_UNAWARE = 0,
PROCESS_SYSTEM_DPI_AWARE = 1,
PROCESS_PER_MONITOR_DPI_AWARE = 2
}
public enum DPI_AWARENESS_CONTEXT
{
DPI_AWARENESS_CONTEXT_UNAWARE = 0,
DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = 1,
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = 2,
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = 3
}
Windows DPI scaling can be a nightmare, particularly when the system DPI is not suitable for specific applications. To get around this, you can force specific applications to increase their DPI setting. This can be done by right-clicking on the application's shortcut, selecting 'Properties', and going to the 'Compatibility' tab. From here, you can check the box next to 'Override high DPI scaling behavior', select 'System (Enhanced)' from the drop-down menu, and then click 'Apply' and 'OK'. Additionally, you can use the example code block provided to adjust the DPI settings in a specific application.
References
-
Types of References:
- Books
- Articles
- Online Resources