Requires: GfaWinx.lg32
Converts pixels based on a 96 dot-per-inch resolution to DPI physical pixels or the DPI resolution of Me.
pixels = ScaleToDpi(pixels96 [,dpi%])
pixelsng = ScaleToDpiSng(value! [,dpi%])
dpi%, pixels, pixels96 | : integer |
pixelsng, value! | : single |
The 96 dots-per-inch coordinate system is always the point of reference. A pixel in this coordinate system is a logical pixel. The number of physical pixels required to display 1 logical pixel can be calculated with ScaleToDpi(). When a window is on a regular 96 dots-per-inch display the physical pixel is equal to the logical pixel. On a high-resolution monitor (and a dpi-aware program) the number of physical pixels for a specified number of logical pixels can be calculated with ScaleToDpi(). By default, ScaleToDpi() calculates the pixels for Me if the dpi% argument is omitted. Otherwise the application may pass a dpi value to use in the calculation.
ScaleToDpi is used in a dpi-aware program to scale the window's contents to the display's DPI.
ScaleToDpiSng works exactly like ScaleTo Dpi except that it takes and returns single expression operands.
NOTE: The above example will not run correctly as it relies on an embedded file which is not present in the syntax. The programme with full resources can be found in GFABASIC/Samples/ScaleToDpi.g32.
Note: These commands are obsolete and are included for backwards compatibility reasons only. See WM_DPICHANGED and other linked pages for up to date methods of scaling to DPI.
The ScaleToDpi function obtains the Dpi for the window and calculates the number of physical pixles using the Scale: Scale(pixels96, WinDpi, 96) which is equal to the formula 'pixels96 Mul WinDpi Div 96'.
For performance reasons the application might avoid the ScaleToDpi function and use the Scale function instead. The window's DPI can be obtained from WinDpi([hWnd]). Each time ScaleToDpi is called it obtains the DPI for the window, which of course slows down execution time. Using Scale directly in the program requires only one call to WinDpi().
To develop dpi-aware apps you'll need two monitors, one regular 96 dots-per-inch display to run GB and one high-resolution display to run the program. In addition, the manifest of GfaWin32.exe must include the dpiAwareness tag. The Bin directory contains a dpimanifest that needs to be renamed to GfaWin32.exe.manifest. After restarting GB the IDE is dpi-aware and will be displayed according the display's DPI. On a high-resolution display the IDE and its font will be very small, hence the need for a second regular monitor to run the IDE.
DpiAwareness, Scale, ScaleXYWHToDpi, WinDpi
{Created by Sjouke Hamstra; Last updated: 23/02/2022 by James Gaite}