Làm thế nào để lấy được giá trị scale and layout của window?

Liên hệ QC
Tôi tuân thủ nội quy khi đăng bài

namvu230397

Thành viên hoạt động
Tham gia
12/10/21
Bài viết
173
Được thích
77
Nghề nghiệp
Kỹ sư công trình giao thông
Không biết em đăng bài tại chủ đề này có đúng hay không, nếu sai thì bác quản trị chuyển cho đúng giúp em với nhé. Các bác cho em hỏi, có cách nào (dùng code) lấy được giá trị scale and layout của window không. Em đang thiết kế ribbon excel, dùng tự tạo để làm icon cho button, để scale layout 100% thì không sao, nhưng nếu để một giá trị khác icon sẽ bị nhoè
 
Bạn tham khảo tại: https://stackoverflow.com/questions/54861661/get-windows-display-zoom-value
PHP:
Option Explicit

Private Const LOGPIXELSX As Long = 88

#If VBA7 Then
    Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hdc As LongPtr, ByVal nIndex As Long) As Long
    Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
    Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hWnd As LongPtr, ByVal hdc As LongPtr) As Long
    Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
    Private Declare PtrSafe Function EnumDisplayMonitors Lib "user32" (ByVal hdc As LongPtr, ByRef lprcClip As Any, ByVal lpfnEnum As LongPtr, ByVal dwData As Long) As Long
#Else
    Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    Private Declare Function GetActiveWindow Lib "user32" () As Long
    Private Declare Function EnumDisplayMonitors Lib "user32" (ByVal hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As Long
#End If

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

    Dim iDPI As Long
    iDPI = -1

    If (hdcScreen) Then
        iDPI = GetDeviceCaps(hdcScreen, LOGPIXELSX)
        ReleaseDC hWnd, 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%
 
Tôi nhớ là file Icon nó có nhiều lớp với độ phân giải từ thấp đến cao mà bạn.
 
Web KT
Back
Top Bottom