Jump to content

Recommended Posts

Posted (edited)

Ok what im trying to find is a way to give me the actual screen size

e.g. 15.4", 15.6", 17" etc

This will be used primarily for laptops

Is there a way to calculate it from Desktop resolution maybe?

Or is it held anywhere o the pc registry etc?

Ive been looking round and the only thing i could find was a reference to this

and using

JSThePatriot script CompInfo

"PixelsPerXLogicalInch: "

"PixelsPerYLogicalInch: "

and

"ScreenHeight: "

"ScreenWidth: "

from the _ComputerGetMonitors() section it gives me

96 for both the pixels per inch

1920 x 1080 for the other two

1920 / 96 = 20

1080 / 96 = 11.25

This is close but not accurate and im not sure how a diagonal could be calculated from the results?

Any ideas

Edited by Chimaera
Posted (edited)

Have in mind the size of the physical pixel....

#include <GDIPlus.au3>
_GDIPlus_Startup()
ConsoleWrite(ScreenSize()  & " inch" & @CRLF)
_GDIPlus_Shutdown()

Func ScreenSize()
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0)
    $aDPI_w = DllCall($ghGDIPDll, "uint", "GdipGetDpiX", "handle", $hGraphic, "float*", 0)
    $aDPI_h = DllCall($ghGDIPDll, "uint", "GdipGetDpiY", "handle", $hGraphic, "float*", 0)
    _GDIPlus_GraphicsDispose($hGraphic)
    Return Round(Pixel_Distance(0, 0, @DesktopWidth, @DesktopHeight) / $aDPI_w[2], 2)
EndFunc

Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem
    Local $a, $b
    If $x2 = $x1 And $y2 = $y1 Then Return 0
    $a = $y2 - $y1
    $b = $x2 - $x1
    Return Sqrt($a * $a + $b * $b)
EndFunc   ;==>Pixel_Distance

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

The math in there makes my head spin, i looked up the therom on Google but geez difficult stuff

That works except it returns 22.95 inch

Yet my monitor is 24 inch

How do i reconcile the difference?

Edit and is it because im using a desktop?

Edited by Chimaera
Posted (edited)

The math in there makes my head spin, i looked up the therom on Google but geez difficult stuff

That works except it returns 22.95 inch

Yet my monitor is 24 inch

How do i reconcile the difference?

Edit and is it because im using a desktop?

As I mentioned before it depends on the physical pixel size.

E.g. a notebooks screen is a 17" screen and can display 1920x1080 and a monitor is a 22" with same resolution. You see calculating the pixels size at a specific DPI cannot give you the exact screen size.

@czardas: look at the Pixel_Distance() function above. ;)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

There is a Vista+ WMI class called WmiMonitorBasicDisplayParams. This one comes pretty close for my primary display (reports 27,15" for my 27"), but sadly it completely fails for my secondary (TV) display (reports 28,9" for my 47").

_WmiMonitorBasicDisplayParams()

Func _WmiMonitorBasicDisplayParams()
    Local $strcomputer = "."
    Local $objWMIServiceWMI = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!" & $strcomputer & "rootWMI")
    If IsObj($objWMIServiceWMI) Then
        ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa394535%28v=vs.85%29.aspx
        $WMIWmiMonitorID = $objWMIServiceWMI.ExecQuery("SELECT * FROM WmiMonitorBasicDisplayParams WHERE Active='True'")
        For $objComputer In $WMIWmiMonitorID
            ConsoleWrite($objComputer.MaxHorizontalImageSize & @CRLF)
            ConsoleWrite($objComputer.MaxVerticalImageSize & @CRLF)
            ConsoleWrite((Pixel_Distance(0, 0, $objComputer.MaxHorizontalImageSize, $objComputer.MaxVerticalImageSize) / 2.54) & @CRLF & @CRLF)
        Next
    EndIf
EndFunc   ;==>_WmiMonitorBasicDisplayParams

Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem
    Local $a, $b
    If $x2 = $x1 And $y2 = $y1 Then Return 0
    $a = $y2 - $y1
    $b = $x2 - $x1
    Return Sqrt($a * $a + $b * $b)
EndFunc   ;==>Pixel_Distance
Edited by KaFu
Posted

A little update

I did some testing at work on a number of laptops and one desktop on kafu's suggestion

And these were the results

Desktop

MaxHorizontalImageSize 34 / MaxVerticalImageSize 27 / Resolution 1280 x 1024 / Result 17.11 Actual = 34.1 | 27.3 [17.0"]

Laptop

MaxHorizontalImageSize 31 / MaxVerticalImageSize 19 / Resolution 1366 x 768 / Result 15.35 Actual = 34.6(cm)| 19.8(cm) [15.6"]

MaxHorizontalImageSize 33 / MaxVerticalImageSize 21 / Resolution 1280 x 800 / Result 15.41 Actual = 33.1(cm) | 20.8(cm) [15.4"]

MaxHorizontalImageSize 33 / MaxVerticalImageSize 21 / Resolution 1280 x 1024 / Result 15.41 Actual = 33.1(cm)| 20.9(cm) [15.4"]

MaxHorizontalImageSize 38 / MaxVerticalImageSize 21 / Resolution 1600 x 900 / Result 17.11 Actual = 38.2(cm) | 21.5(cm) [17.3"]

MaxHorizontalImageSize 34 / MaxVerticalImageSize 19 / Resolution 1366 x 768 / Result 15.35 Actual = 34.4(cm) | 19.5(cm) [15.6"]

MaxHorizontalImageSize 34 / MaxVerticalImageSize 19 / Resolution 1366 x 768 / Result 15.35 Actual = 34.4(cm) | 19.5(cm) [15.6"]

MaxHorizontalImageSize 37 / MaxVerticalImageSize 23 / Resolution 1440 x 900 / Result 17.17 Actual = 36.8(cm) | 23.1(cm) [17.0"]

Thought i would post them just so you guys can see them

Posted (edited)

Thanks for the testing and results.

Overall a good approximation!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...