Determine if screen size fonts/text/apps/etc is set above 100%

Started by JTaylor, July 26, 2022, 08:38:08 PM

Previous topic - Next topic

JTaylor

How can I determine if screen size for fonts/text/apps/etc is set above 100%?   Not finding the right words to search for I assume.

Thanks.

Jim

td

There may be easier ways to accomplish it but this is the first one that comes to mind. To get the logical pixels, you can use the Win32 function GetDeviceCaps with the LOGPIXELSX in the index parameter. You will first need to get a DC handle to use as the first parameter to the function. Logical pixels provided by LOGPIXELSX are the logical pixels per inch in the horizontal direction.

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Thanks.   Surprised this isn't part of WinMetrics() or SysParamInfo().   Seems like something many people would want to know.   Although, I guess this is the first time it has come up for me in over 25 years using WinBatch so maybe not :)

Jim

td

Hate to see you tire out your fingers so in case you haven't already done it, here is a quick and dirty example that may speed things a bit.

Code (winbatch) Select
;; Note: If WinBatch was not manifested to be DPI aware
;; this would not work.  But it is so it does.

hDC = DllCall("User32.dll", long_ptr:"GetDC", lpnull)

LOGPIXELSX = 88
nPixPerInchX = DllCall("Gdi32.dll", long:"GetDeviceCaps", long:hDC, long:LOGPIXELSX)

;; 96 is the default Windows scaling.
nScallingPercent = (nPixPerInchX/96.0) * 100

x =  DllCall("User32.dll", long:"ReleaseDC", lpnull, long:hDC)

Message("Desktop Scalling",  nScallingPercent:"%%")

;; This would require Windows 10 - 1604 or later
;;nPixPerInchX10 = DllCall("User32.dll", long:"GetDpiForWindow", long:DllHwnd(""))

exit
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

I should have responded earlier so as to save you the time.  I did get it working.  I added it as a function to my Extender just in case I needed it for other things.    I was going to ask though.   Is 96 always the base?   I made that assumption in solving the problem and I see you used it as well.

Thanks.   I appreciate the code.   Always good for comparison.

Jim

td

Yes, 96 logical pixels per inch is always considered 100% scaling.

As far as wasting time goes. Spending a few minutes writing that script turned out not to be a waste of time at all.  Happened to find a bug in the DllCall function (not demonstrated by the example as presented.)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor