如何获得显示器尺寸 [英] How to get monitor size
问题描述
在我的项目中,我需要确定监视器/屏幕的大小.我可以使用以下代码获取屏幕分辨率
In my project I need to determine the size of the monitor/screen. I can get the screen resolution using following code
X = fPixelsToTwips(GetSystemMetrics(SM_CXSCREEN), "X") '
Y = GetSystemMetrics(SM_CYSCREEN)
这给了我正确的屏幕分辨率.但是我有一个13.6英寸的笔记本电脑屏幕,我的朋友有15.6英寸的笔记本电脑屏幕.两者具有相同的屏幕分辨率1366 * 768.但是屏幕尺寸是不同的.那么如何确定显示器的屏幕尺寸呢?这对我的项目非常重要.
This gives me the correct screen resolution. But I have a 13.6" laptop screen and my friend has 15.6" laptop screen. Both has same screen resolution 1366*768. But the screen size is different. So how can I determine screen size of monitor? This is very important for my project.
推荐答案
您可以点击WMI的WmiMonitorBasicDisplayParams
以获得有关显示器的一些信息.使用Windows 7,我可以使用此代码成功显示两个显示器的对角线长度.
You can tap into WMI's WmiMonitorBasicDisplayParams
to get some information about your display. I was successfully able to display the diagonal length of both displays with this code using Windows 7.
Option Explicit
Sub Test()
Dim WMIObject As Object
Dim WMIResult As Object
Dim WMIItem As Object
Set WMIObject = GetObject("winmgmts:\\.\root\WMI")
Set WMIResult = WMIObject.ExecQuery("Select * From WmiMonitorBasicDisplayParams")
Dim Diagonal As Double
Dim Width As Double
Dim Height As Double
Dim Counter As Integer
Counter = 1
For Each WMIItem In WMIResult
Width = WMIItem.MaxHorizontalImageSize / 2.54
Height = WMIItem.MaxVerticalImageSize / 2.54
Diagonal = Sqr((Height ^ 2) + (Width ^ 2))
MsgBox "Your monitor # " & Counter & " is approximiately " & Round(Diagonal, 2) & " inches diagonal"
Counter = Counter + 1
Next
End Sub
一些其他参考可能会对您有所帮助.
Some other references that may help you.
- VBScript and WMI to capture display information
- PowerShell and WMI to capture display information
- C# to capture display information
- System Information using VBA and WMI
这篇关于如何获得显示器尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!