Enabling DPI mode

When you run the application from the PowerBuilder IDE, the DPI mode has no effect to the application UI.

The DPI scaling mode will work only when the application is compiled as an executable file and run on Windows 11 or later or Windows Server 2016 or later.

To enable the DPI mode, follow these steps:

  1. Set the DPI scaling mode before any window is opened.

    For applications developed in PowerBuilder 2025 or later, the "Per-Monitor (V2) DPI Awareness" mode will be automatically selected in the IDE painter.

    For applications upgraded from an earlier version to PowerBuilder 2025 or later, the "DPI Unaware" mode will be automatically selected. You will need to explicitly set the mode to "Per-Monitor (V2) DPI Awareness".

    You can set the mode in the IDE painter or in the scripts:

    • In the IDE painter

      Open the application object painter, go to the application's Properties view, select PerMonitorV2(4) --- Default from the HighDpiMode property listbox.

      The HighDPIMode property can only be set in the IDE. It cannot be set in the script; but you can get its property value in the script. The value can be one of the following: 0 - None, 1 - DpiUnaware, 2 - SystemAwareness, 3 - PerMonitor, 4 - PerMonitorV2 (Default), and 5 - DpiUnawareGdiScaled.

    • In the scripts

      Call the Application SetHighDPIMode function before any window is opened (for example, in the Application's Open event). Once the mode is set successfully to any value between 1 and 5 (inclusive); the subsequent SetHighDPIMode function calls will fail and return -1.

    Note

    Once the mode is set successfully to any value other than 0 (None) (in the IDE or in the scripts), it cannot be changed in the script any more.

  2. Enable dynamic DPI awareness so that the application UI scales properly when moving across screens with different DPI settings.

    Use the window DPIChanged event to handle DPI change notifications at runtime, so you can adjust the size and layout of windows, controls, and fonts to match the new DPI.

    You can also use the GetDpiForWindow function to query the current DPI for a window or control and implement DPI-aware custom drawing or layout adjustments. This is especially useful when mixing standard PowerBuilder controls with manual rendering logic.

  3. Compile the application as an executable file.

    The DPI-related functions, events, and properties only work in the compiled application (they will not work in IDE).

  4. Run the application executable file, and then move the application between monitors with different DPI settings or change the Windows scaling size to verify the effect.

Note

For all desktop applications (including PowerBuilder applications), DPI mode can be configured in multiple ways and will be applied in the following order:

application executable property (highest priority) > manifest file > Windows API (lowest priority)

In PowerBuilder, the DPI-related function and property set the DPI mode through the Windows API (specifically, SetProcessDpiAwarenessContext), which means

1) If the mode has already been specified through the application executable property or manifest file, the PowerBuilder HighDPIMode property and SetHighDPIMode function will not override those settings.

2) The Windows API (SetProcessDpiAwarenessContext) is supported only on Windows 11 or later, or Windows Server 2016 or later. On earlier systems, the DPI mode will default to None(0).