WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: JTaylor on July 26, 2022, 08:38:08 PM

Title: Determine if screen size fonts/text/apps/etc is set above 100%
Post by: JTaylor on July 26, 2022, 08:38:08 PM
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
Title: Re: Determine if screen size fonts/text/apps/etc is set above 100%
Post by: td on July 26, 2022, 09:48:41 PM
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.

Title: Re: Determine if screen size fonts/text/apps/etc is set above 100%
Post by: JTaylor on July 27, 2022, 06:20:23 AM
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
Title: Re: Determine if screen size fonts/text/apps/etc is set above 100%
Post by: td on July 27, 2022, 11:11:16 AM
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
Title: Re: Determine if screen size fonts/text/apps/etc is set above 100%
Post by: JTaylor on July 27, 2022, 12:00:28 PM
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
Title: Re: Determine if screen size fonts/text/apps/etc is set above 100%
Post by: td on July 27, 2022, 12:13:39 PM
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.)
Title: Re: Determine if screen size fonts/text/apps/etc is set above 100%
Post by: JTaylor on July 27, 2022, 12:53:17 PM
Excellent.  Thanks again.



Jim