HeaderPane
Main
Hide
Share Link
Print

Per-Monitor DPI and Scaling

SftDate/DLL 2.0 is Per-Monitor v2 DPI-aware. An SftDate or SftCalendar control hosted on a Per-Monitor v2 aware top-level window follows the DPI of the monitor it is on and redraws when its window moves to a monitor of a different DPI or when the system DPI changes. The control owns the metrics it controls; the caller owns the images and fonts it provides.

Host Setup

The host application must declare Per-Monitor v2 DPI awareness. Without a PMv2 declaration, Windows keeps the process in System-aware mode: the DPI is fixed for the process lifetime, the controls do not observe DPI changes, NM_SFTDATE_DPI_CHANGED is never sent, and high-DPI monitors render at System-DPI sizes stretched by Windows. Visual Studio's default application manifest does not declare PMv2 awareness - the developer must opt in explicitly.

Two approaches - pick one:

Application manifest (recommended)

Add a <dpiAwareness> / <dpiAware> element to the application manifest. Both elements are usually included for back-compatibility with older Windows 10 builds:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
    <asmv3:windowsSettings>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
</assembly>

In a Visual Studio C++ project, set Project Properties -> Manifest Tool -> Input and Output -> Additional Manifest Files to the .manifest file above, and set Project Properties -> Manifest Tool -> Input and Output -> DPI Awareness to None, so the manifest tool does not add a second <dpiAware> element; a manifest with two of them keeps the application from starting. The SftDate/DLL samples include their manifest this way.

Runtime API

Alternatively, call SetProcessDpiAwarenessContext at process startup, before any window is created:

SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);

Caveat: This call must run before the first window (including hidden startup dialogs or splash screens) is created. If a window has already been created, Windows rejects the call and the process remains in whichever mode the manifest specified.

Verifying the declaration worked

Quick check at runtime: SftDate_GetDPI returns the DPI of the control's monitor - 96 at 100%, 120 at 125%, 144 at 150%, 192 at 200%. If the returned value never changes as you drag the window between monitors with different scale factors, the host is not in PMv2 mode.

What Scales Automatically

When the host is Per-Monitor v2 aware, the controls scale the metrics they own for the DPI of their monitor, without any caller involvement: the field's border, buttons and check box, the calendar's layout, its previous and next buttons, the time list and the clock face. A control without a font of its own (no WM_SETFONT) uses the Windows message font for its DPI. A field closes its dropdown when its DPI changes. A dropdown opened on another monitor than its field uses the DPI of that monitor, with the field's fonts scaled to it.

What the Caller Controls

SftDate_SetImageScaling defines how the pictures of special dates and of the NM_SFTDATE_DAYFORMATTING notification follow the DPI:

SettingDescription
SFTDATE_IMAGESCALING_ASIS (default)Pictures are drawn at their native pixel size. Pictures supplied for 96 DPI look physically smaller on a high-DPI monitor.
SFTDATE_IMAGESCALING_STRETCHPictures are treated as designed for 96 DPI and are scaled by DPI / 96.

SftDate_GetImageScaling returns the setting. No function of SftDate/DLL takes a pixel size from the application: the controls size all their parts from the font and the DPI of the monitor.

Caller Responsibilities on DPI Change

When the DPI of a control changes, NM_SFTDATE_DPI_CHANGED is sent to the parent window. The application should:

SftDate_GetDPI returns the new DPI while the notification is handled.

Platform note: Per-Monitor v2 DPI awareness requires Windows 10 version 1703 or later.


Last Updated 11/26/2026 - (email)
© 2026 Softel vdm, Inc.