获取Windows显示缩放值 [英] Get Windows display zoom value

查看:72
本文介绍了获取Windows显示缩放值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以获取Windows的显示缩放值吗?图片中的200%正是我想要得到的.

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

推荐答案

您可以通过WIN32-API调用来检索此信息

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

这将导致 192 ,例如 200%:

  • 96 –较小的100%
  • 120 –中等125%
  • 144 –更大的150%
  • 192 –特大200%
  • 240 –自定义250%
  • 288 –自定义300%
  • 384 –自定义400%
  • 480 –自定义500%

这篇关于获取Windows显示缩放值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆