HeaderPane
Main
Hide
Share Link
Print

Per-Monitor DPI and Scaling

SftBox/DLL 6.0 is Per-Monitor v2 DPI-aware. A combo box control hosted on a Per-Monitor v2 aware top-level window follows the DPI of the monitor it is on and re-renders 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. Two opt-in settings let the caller hand the scaling of images and pixel values over to the control as well.

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 combo box does not observe DPI changes, SFTBOXN_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, or edit the auto-generated manifest directly.

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: GetDPI on the combo box returns the current monitor's DPI - 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 combo box scales the metrics it owns for the DPI of its monitor, without any caller involvement: the scroll bars, the dropdown button, its built-in arrow and the sizing box of the dropdown portion. The dropdown portion always uses the DPI of the combo box.

What the Caller Controls

Two independent settings let the caller choose whether caller-supplied images and caller-supplied pixel values also scale with DPI. Both default to no automatic scaling, so the application is in full control.

SettingCoversASIS (default)STRETCH
SetImageScalingEvery image the control draws: item pictures, label pictures, cell pictures, column header, row header and row/column header pictures, dropdown button pictures and expand/collapse buttons.SFTBOX_IMAGESCALING_ASIS - Images are drawn at their native pixel size. Images supplied for 96 DPI look physically smaller on a high-DPI monitor.SFTBOX_IMAGESCALING_STRETCH - Images are scaled by DPI / 96.
SetPixelScalingPixel dimensions set by the application: column widths (SFTBOX_COLUMN, width and minWidth), indentation (SetIndentation), row header width (SetRowHeaderWidth), horizontal extent (SetHorizontalExtent), item height minimum and maximum (SetItemHeightMinMax), dropdown portion width and height in pixels (SetDroppedWidth, SetDroppedHeight).SFTBOX_PIXELSCALING_ASIS - Values are used as set, in physical screen pixels. A column width of 100 is 100 pixels on any monitor.SFTBOX_PIXELSCALING_STRETCH - Values are interpreted as 96-DPI reference pixels. A column width of 100 is 100 pixels at 100%, 150 pixels at 150%, 200 pixels at 200%. The functions which return these values always return them as set, so saved settings stay portable.

The settings are also available as the imageScaling and pixelScaling members of the SFTBOX_CONTROL structure (see SetControlInfo). GetImageScaling and GetPixelScaling return the current settings.

Caller Responsibilities on DPI Change

When the DPI of the combo box changes, the dropdown portion is hidden if it is currently shown and SFTBOXN_DPI_CHANGED is sent to the parent window. The application should:

GetDPI returns the new DPI while the notification is handled. Once the notification has been handled, the combo box recalculates its layout.

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


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