Notifications
Clear all

[Closed] How to get current screen's dpi

Hi
I am trying to get the scaling of current screen,in Windows 10,there are 100%,120% 150%,I find a code maybe can get it,but it does not work,anyone can help?

(dotNetClass "System.Windows.Media.VisualTreeHelper").GetDpi()

8 Replies

DPI is for text “size”, not for screen resolution (at least in Win 7).

So how to get current screen’ scaling?

Sorry, don’t know.
Dont have problems with win 10 or 4k monitors cause I’m not using them.
Maybe look for sysinfo in help
Or thru win native tools, why are you using max for that?

Edit:
There’s sysInfo.DesktopSizeUnscaled new in 2017
and sysinfo.desktopSize from before

The reason is the text of my script runs in some Windows 10 system display are incomplete if using 125% or 150%,I need to detect whether user’s screen is scaled,then I can adjust the fonts size,the sysinfo.desktopSize maybe should not work,thanks for help.

That is a topic has a command can do it via c#,but I don’t know how to use it in maxscript

C# code:
double factor = System.Windows.PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice.M11;

I find a solution by myself,just get the value of regedit:

and
https://www.tenforums.com/tutorials/5990-change-dpi-scaling-level-displays-windows-10-a.html ?cf_chl_jschl_tk=34cded640fb53a8df3d86369dea573b9c4429036-1606099778-0-AUEjx7iKrOJSAi-kHUd6rmP4ejzZ9A5j8b7GAtGVxOew5-pT55Tdu43qFfNgeQDm0Q05cajJIHjctqpQNKsUKb_2fn4z8XmQS2j4lzdb-CEbJA089urUaBYmVUKKwUIwnm7p5H-GNeIFDGnpRiX-dn8AD2HmHhWAXeg2kW-KAc5fufResg8egS38lcMh2a3F6sXKouWEhVxWjj1LBYp812Vvoz-ISK_3lMbrA0AOuK53vpijQ6iNJtAlTjfRL9CNogaANK7D_RuqSnh07iLgCXG9xwu8rV5DVtPp3AtssXvSjiWUaPE_rBTfd1IBt_Z2iP0OY29ExmaK5tesCrDa2fqtG4VY-fWOSE_XgYrjW_CKfKsiiI8seBhtePLi6IUDPEbfELyuRhlOLGHUDYzjr1s

Thanks for help!

 MZ1

This are various methods:

what about GetUIScaleFactor() ? not good enough ?
delivers 1.5 at 150% scaling

 MZ1

It depends on what you want to do with that number. Take a look at this example:

public static System.Windows.Point GetScreenSize()
{
    System.Windows.Media.Matrix transform = (new HwndSource(new HwndSourceParameters())).CompositionTarget.TransformToDevice;
    return transform.Transform(new System.Windows.Point(SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight));
}