|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
- Private Declare PtrSafe Function MonitorFromWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal dwFlags As Long) As LongPtr
- Private Declare PtrSafe Function GetMonitorInfo Lib "user32" Alias "GetMonitorInfoA" (ByVal hMonitor As LongPtr, ByRef lpmi As Any) As Long
- Private Declare PtrSafe Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, ByRef lpDevMode As Any) As Boolean
- Private Declare Function GetActiveWindow Lib "user32" () As LongPtr
- Private Type RECT
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
- Private Type MONITORINFOEX
- cbSize As Long
- rcMonitor As RECT
- rcWork As RECT
- dwFlags As Long
- szDevice As String * 32
- End Type
- Type DevMode
- dmDeviceName(0 To 31) As Byte
- dmSpecVersion As Integer
- dmDriverVersion As Integer
- dmSize As Integer
- dmDriverExtra As Integer
- dmFields As Long
- dmOrientation As Integer
- dmPaperSize As Integer
- dmPaperLength As Integer
- dmPaperWidth As Integer
- dmScale As Integer
- dmCopies As Integer
- dmDefaultSource As Integer
- dmPrintQuality As Integer
- dmColor As Integer
- dmDuplex As Integer
- dmYResolution As Integer
- dmTTOption As Integer
- dmCollate As Integer
- dmFormName(0 To 31) As Byte
- dmLogPixels As Integer
- dmBitsPerPel As Long
- dmPelsWidth As Long
- dmPelsHeight As Long
- dmDisplayFlagsUnion As Long ' Union member: 'dmNup' or 'dmDisplayFlags'
- dmNup As Long ' Union member: 'dmNup' or 'dmDisplayFlags'
- End Type
- Public Function GetScreenScale() As Double
- Dim hMonitor As LongPtr
- hMonitor = MonitorFromWindow(GetActiveWindow, 0&)
-
- Dim miex As MONITORINFOEX: miex.cbSize = Len(miex)
- Call GetMonitorInfo(hMonitor, miex)
-
- Dim dm As DevMode: dm.dmSize = Len(dm)
- Call EnumDisplaySettings(miex.szDevice, -1&, dm)
-
- Dim cxLogical As Long: cxLogical = (miex.rcMonitor.Right - miex.rcMonitor.Left)
- Dim cyLogical As Long: cyLogical = (miex.rcMonitor.Bottom - miex.rcMonitor.Top)
-
- Dim cxPhysical As Long: cxPhysical = dm.dmPelsWidth
- Dim cyPhysical As Long: cyPhysical = dm.dmPelsHeight
-
- GetScreenScale = ((cxPhysical / cxLogical) + (cyPhysical / cyLogical)) / 2#
- End Function
复制代码 |
|