B4J Question How to get Windows Scale Factor (Text Size, Apps, Layout)

Magma

Expert
Licensed User
Longtime User
Hi there...

is the any inline java or something to get windows scale factor ?
1663954493363.png


Found a powershell script... but I am wondering if anything else:

B4X:
Add-Type @'
  using System;
  using System.Runtime.InteropServices;
  using System.Drawing;

  public class DPI {
    [DllImport("gdi32.dll")]
    static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

    public enum DeviceCap {
      VERTRES = 10,
      DESKTOPVERTRES = 117
    }

    public static float scaling() {
      Graphics g = Graphics.FromHwnd(IntPtr.Zero);
      IntPtr desktop = g.GetHdc();
      int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
      int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);

      return (float)PhysicalScreenHeight / (float)LogicalScreenHeight;
    }
  }
'@ -ReferencedAssemblies 'System.Drawing.dll'

[Math]::round([DPI]::scaling(), 2) * 100

Thanks in advance.
 
Solution
Try this (it is from BCTextEngine):
B4X:
Dim fx As JFX
Dim jo As JavaObject = fx.PrimaryScreen
Dim scale As Float = jo.RunMethod("getOutputScaleX", Null)

Magma

Expert
Licensed User
Longtime User
This is not only works... but works "live" (no need to reboot if changed the same time)...

For the history... found that before Erel's gave me solution:
HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics
AppliedDPI as INT --- 96 dpi (if 100%)
So if was for example 144... 144/96=1.50

But if changed and not reboot - not getting the new value...

@Erel... Do i need to get "getOutputScaleY" too... is there possiblity to be a different value ?
 
Upvote 0
Top