DPI Aware Windows app with CMake

If you are developing Windows applications with CMake, you may have noticed that your user interface looks blurry or pixelated on high-DPI monitors. This is because by default, Windows does not treat your application as DPI aware, meaning that it does not scale properly according to the monitor’s resolution and DPI settings. This can result in a poor user experience and a loss of quality for your app.

Fortunately, there is a simple way to fix this issue in CMake, without having to modify any code or use any external tools. All you need to do is create a manifest file that declares your application as DPI aware, and add it to your CMake target sources. A manifest file is an XML file that contains metadata about your application, such as its name, version, dependencies, and settings. By adding a DPI awareness setting to your manifest file, you can tell Windows how to scale your application correctly on different monitors.

  1. Add a new file dpi-aware.manifest to the sources of your app. It should look like the following:
<?xml version="1.0"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
  1. In CMakeLists.txt add the following:
target_sources(myapp PRIVATE dpi-aware.manifest)

And voila, the app will be super crisp! That’s all you need to do to make your users happy and satisfied.

To contact me, send an email anytime or leave a comment below.