Getting Windows scaling factor using declares

On my Windows 10 system HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI does not exist.
I suspect this varies between 7, 8 and 10.

Hi Hamish…
I’ve just done a very quick test based on the orignal code posted, but with some more calls to GetDeviceCaps using the
values…

const HORZRES = 8
const VERTRES = 10
const DESKTOPHORZRES = 118
const DESKTOPVERTRES = 117

I’m using Win.8.1 and I get some differences between the xxxxRES and DESKTOPxxxRES values if I set the screen scale slider to invoke scaling. I don’t know if these can be used to to get the scale values you are looking for, but it may be worth a look.

This was done without any calls or mainifest to get HiDPI set for the app.

Well spotted Chris, I cant even find a reference to DESKTOPHORZRES on the GetDeviceCaps function page.

This works for anyone else looking to find the scaling factor of the primary screen:

[code] Declare Function GetDC Lib “user32” (hWnd As Ptr) As Ptr
Declare Function GetDeviceCaps Lib “gdi32” _
(hdc As Ptr, nIndex As Integer) As Integer
Declare Sub ReleaseDC Lib “user32” (hWnd As Ptr, hdc As Ptr)

const HORZRES = 8
const VERTRES = 10
const DESKTOPHORZRES = 118
const DESKTOPVERTRES = 117

Dim hdc As Ptr = GetDC(Nil)
system.DebugLog( str(GetDeviceCaps(hdc, DESKTOPHORZRES) / GetDeviceCaps(hdc, HORZRES)) )
system.DebugLog( str(GetDeviceCaps(hdc, DESKTOPVERTRES) / GetDeviceCaps(hdc, VERTRES)) )
ReleaseDC(Nil, hdc)[/code]

I’m resurrecting this thread because I’m revisiting this code and don’t seem to be able to use it to work out the scale factor on Windows 10 with the latest version of Xojo and its Hi-DPI mode.

At 200% scale factor, both DESKTOPHORZRES and HORZRES are being reported as 2560, the native resolution of my laptop’s display.

What am I missing here?

Can you get the scale factor from the Graphics object in the WIndow.Paint event (ScaleX, ScaleY)?

Don’t really know how it works on Windows; but after dealing with Retina displays on the macOS for 5 years; I would suggest looking at something that is specific to the window, rather than the screen. The reason being is that window may or may not be on a high resolution display.

If that works, that’s actually pretty darn cool! How about using Window.BitmapForCaching ( width As Integer, height As Integer ) passing in 100 x 100 and then measuring the image that comes out?

[quote=344318:@Tom Catchesides]I’m resurrecting this thread because I’m revisiting this code and don’t seem to be able to use it to work out the scale factor on Windows 10 with the latest version of Xojo and its Hi-DPI mode.

At 200% scale factor, both DESKTOPHORZRES and HORZRES are being reported as 2560, the native resolution of my laptop’s display.

What am I missing here?[/quote]

Do you have multiple screens as the code above only works for the primary screen.

Thanks, Paul: that turned out to be perfect for my needs. I feel like an idiot for not thinking of this, but I know exactly how my thought process went:

“Oh, look, here are some declares that I barely understand and they seem to be returning the wrong result. I wonder how I can work around that? Probably some more declares that I barely understand, rather than something really simple that Xojo has added in the last couple of years!”