Determine physical size of Monitor

Viewed 118

I use the following to get the physical width and height of a monitor (e.g., in millimeters or inches)

dimX = GetDeviceCaps(hDC, DevCap.HORZSIZE)
dimY = GetDeviceCaps(hDC, DevCap.VERTSIZE)

It appears to only work for Windows10, and not Windows7

Can someone confirm?

VB6 code

Private Sub Command1_Click()

    Dim hWnd As Long
    Dim hMonitor As Long
    Dim tMonitorInfo As MONITORINFOEX
    Dim hDC As Long

    hWnd = GetActiveWindow()
    hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONULL)
    
    tMonitorInfo.cbSize = Len(tMonitorInfo)
    Call GetMonitorInfo(hMonitor, tMonitorInfo)
    
    hDC = CreateDC(tMonitorInfo.szDevice, 0, 0, 0)

    Dim dimX As Double  'monitor width  in millimeters
    Dim dimY As Double  'monitor height in millimeters

    dimX = GetDeviceCaps(hDC, DevCap.HORZSIZE)
    dimY = GetDeviceCaps(hDC, DevCap.VERTSIZE)

    MsgBox "monitor size = " & _
           Round(dimX / 25.4, 2) & """" & " x " & _
           Round(dimY / 25.4, 2) & """"
    
    DeleteDC (hDC)
    
End Sub
0 Answers
Related