Screen display size

前端 未结 7 990
长情又很酷
长情又很酷 2021-01-19 03:50

Hi I\'m writing a graphics program and I\'ve been searching for a way to get the physical size of the screen being used. I can get the size of the screen in pixels and also

相关标签:
7条回答
  • 2021-01-19 04:29

    OK, following Andreas' comments I performed some search and found solution for windows. You can use WMI. WMI can be invoked from java using one of the interoperability tools (jinterop, jintegra, jawin) or by execution of external script (VBScript or JScript). The following script is an example:

     strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" _
        & strComputer & "\root\cimv2")
    Set colSoftware = objWMIService.ExecQuery _
        ("Select * from Win32_DesktopMonitor")
    
    For Each objSoftware in colSoftware
        Wscript.Echo "Caprion: " & objSoftware.Caption
        Wscript.Echo "Description: " & objSoftware.Description
        Wscript.Echo "PixelsPerXLogicalInch: " & objSoftware.PixelsPerXLogicalInch
        Wscript.Echo "ScreenWidth: " & objSoftware.ScreenWidth
    Next
    

    save it in file screen.vbs and run it using command line cscript screen.vbs Then ScreenWidth/PixelsPerXLogicalInch gives you width in inches.

    See [http://msdn.microsoft.com/en-us/library/aa389273%28v=VS.85%29.aspx][1] for more information. I believe that solution for other OS types also exist.

    0 讨论(0)
提交回复
热议问题