Option Compare DatabaseOption ExplicitPrivate Declare Function apiGetDC Lib "user32" Alias "GetDC" _ (ByVal hwnd As Long) As LongPrivate Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" _ (ByVal hwnd As Long, ByVal hdc As Long) As LongPrivate Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" _ (ByVal hdc As Long, ByVal nIndex As Long) As LongPrivate Const LOGPIXELSX = 88Private Const LOGPIXELSY = 90Public Const DIRECTION_VERTICAL = 1Public Const DIRECTION_HORIZONTAL = 0Function fTwipsToPixels (lngTwips As Long, lngDirection As Long) As long
'Function to convert Twips to pixels for the current screen resolution' Accepts: 'lngTwips - the number of twips to be converted' lngDirection - direction (x or y - use either DIRECTION_VERTICAL or DIRECTION_HORIZONTAL) 'Returns:' the number of pixels corresponding to the given twips On Error GoTo E_Handle Dim lngDeviceHandle As Long Dim lngPixelsPerInch As Long lngDeviceHandle = apiGetDC (0) If lngDirection = DIRECTION_HORIZONTAL Then lngPixelsPerInch = apiGetDeviceCaps (lngDeviceHandle, LOGPIXELSX) Else lngPixelsPerInch = apiGetDeviceCaps (lngDeviceHandle, LOGPIXELSY) End If lngDeviceHandle = apiReleaseDC (0 , lngDeviceHandle) fTwipsToPixels = lngTwips / 1440 * lngPixelsPerInchfExit: On Error Resume Next Exit FunctionE_Handle: MsgBox Err.Description, vbOKOnly vbCritical, "Error:" & Err.Number Resume fExitEnd FunctionFunction fPixelsToTwips (lngPixels As Long, lngDirection As Long) As Long