Get Windows display zoom value

大憨熊 提交于 2019-12-25 02:53:55

问题


Is there any way to get display zoom value of Windows? The 200% in the picture is exactly what I would like to get.

This question is only half the means to achieve another purpose, which is formulated in that question: Excel Shape position disturbed by Windows Display Zoom settings


回答1:


You can retrieve this information with a WIN32-API call

Option Explicit

Private Const LOGPIXELSX As Long = 88

#If VBA7 Then
    Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hdc As LongPtr, ByVal nIndex As Long) As Long
    Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
    Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As LongPtr, ByVal hdc As LongPtr) As Long
#Else
    Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
#End If

Public Function GetDpi() As Long
    #If VBA7 Then
        Dim hdcScreen As LongPtr
    #Else
        Dim hdcScreen As Long
    #End If
    hdcScreen = GetDC(0)

    Dim iDPI As Long
    iDPI = -1

    If (hdcScreen) Then
        iDPI = GetDeviceCaps(hdcScreen, LOGPIXELSX)
        ReleaseDC 0, hdcScreen
    End If

    GetDpi = iDPI
End Function

This will result in 192 for eg 200%:

  • 96 – Smaller 100%
  • 120 – Medium 125%
  • 144 – Larger 150%
  • 192 – Extra Large 200%
  • 240 – Custom 250%
  • 288 – Custom 300%
  • 384 – Custom 400%
  • 480 – Custom 500%


来源:https://stackoverflow.com/questions/54861661/get-windows-display-zoom-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!