Access/VBA Library

ScreenWidth

Returns the width of the screen.

Syntax

ScreenWidth()
Return value

Long : The width of the screen in twips.

Code
Public Function ScreenWidth() As Long
    Const HWND_DESKTOP As Long = 0
    Const LOGPIXELSX As Long = 88
    Dim lngDC As Long
    Dim TwipsPerPixelX As Single
    
    lngDC = GetDC(HWND_DESKTOP)
    TwipsPerPixelX = 1440& / GetDeviceCaps(lngDC, LOGPIXELSX)
    ReleaseDC HWND_DESKTOP, lngDC
    
    ScreenWidth = GetSystemMetrics32(0) * TwipsPerPixelX
End Function
Systemtag:System

See also

  • GetDC
  • ReleaseDC
  • GetDeviceCaps