Home > Back-end >  VBA Access - Measure Display Unit
VBA Access - Measure Display Unit

Time:11-24

I am currently using a 4K (3840x2160) 28-inch (631.93 mm x 359.78 mm) 60Hz IPS monitor, which according to the manufacturer the pixel per inch (DPI/PPI) value should be 157.35.

However, when I use the GetDeviceCaps function, it returns 144. As I am not very familiar with this topic I would be extremely grateful if someone can explain from where the difference is coming. Last but not least, is there a way to calculate my PPI correctly?

Declare PtrSafe Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal Index As Long) As Long

Public Function returnDPI()

Dim hDC As Long
hDC = GetDC(0)

MsgBox GetDeviceCaps(hDC, 88)
MsgBox GetDeviceCaps(hDC, 90)

End Function

CodePudding user response:

TLDR: you're not measuring what you think you're measuring;

88 and 90 are logical pixels per inch (see this enum and the docs for GetDeviceCaps):

enter image description here

enter image description here

Be aware that these LongPtr types will error on VBA versions before 7 and you would need to do conditional compilation. I didn't include that because this should work on 2010 , and there are plenty of resources out there already for supporting older versions.

  • Related