SetHighDPIMode

Description

Sets the DPI (Dots Per Inch) awareness mode.

Applies to

Application object

Syntax

applicationname.SetHighDpiMode (<HighDpiMode>)

Argument

Description

applicationname

The name of the application object in which you want to set the DPI mode.

HighDpiMode

An integer determines the DPI awareness mode to be used in the application.

  • 0 - None. If a PowerBuilder application is upgraded from an earlier version, it will be set to 0 by default.

  • 1 - DpiUnaware. This is the default behavior in Windows. For the time being, it has the same effect as 0.

  • 2 - SystemAwareness

  • 3 - PerMonitor

  • 4 (Default) - PerMonitorV2. If a new PowerBuilder application is created from scratch, it will be set to 4 by default.

  • 5 - DpiUnawareGdiScaled

For details about the awareness mode, refer to https://learn.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows and https://learn.microsoft.com/en-us/windows/win32/hidpi/dpi-awareness-context.


Usage

The SetHighDPIMode function must be called before any window is opened, for example, it can be called in the Application's Open event.

When the DPI mode is 0, you can call the SetHighDPIMode function to set the awareness mode.

When the DPI mode is any value between 1 and 5 (inclusive) (no matter it is set in the painter or by the SetHighDPIMode function), you cannot call the SetHighDPIMode function to change the mode. The SetHighDPIMode function calls will fail and return -1.

The DPI mode can be set in several ways and will take effect in the following order: application executable property > manifest file > Windows API.

PowerBuilder calls the Windows API to set the awareness mode, therefore please notice the following:

1) If the mode is set successfully in the application executable property or manifest file, PowerBuilder (which calls Windows API to set the mode) will not take effect.

2) The Windows API (SetProcessDpiAwarenessContext) will work only in Windows 10 (version 1703) or later and Windows Server 2016 or later; in the other Windows OS, no mode will be set (the application will run in the None(0) mode).

Return value

Integer.

Returns 1 if the mode is set successfully and -1 if it is not.

Examples

The following code example reads the DPI mode from an INI file and then sets the mode for the application (the scripts should be placed in the Application's Open event, so they can be executed before any window is opened):

// Suppose the HighDPIMode selected in the painter is 0 – None.
Int li_dpimode
Int li_rtrn

// Read the HighDpiMode configuration from an ini file.
li_dpimode = Integer(ProfileString("myapp.ini", "DPI", "HighDpiMode", "4") )

// Change DPI Awareness 
li_rtrn = GetApplication().SetHighDpiMode(li_dpimode)
If li_rtrn <> 1 Then
            Messagebox("SetHighDpiMode Failed: " + String(li_dpimode), String(li_rtrn))
End If