This function is supposed to return the max possible width of a string consisting of the given nof. characters but it it is returning too large a value:
Public Function MaxTextWidth(hwndWindow As Long, lngNofCharacters As Long) As Single
'-------------------------------------------------------------------
'returns the max. width ( in twips ) that would be occupied by the given nof. characters
'-------------------------------------------------------------------
On Error GoTo errHandler
Const strProcedure As String = "MaxTextWidth"
Dim cdsTmp As TEXTMETRIC
Dim lngReturn As Long
lngReturn = GetDC(hwndWindow)
If lngReturn = 0 Then
Err.Raise GetLastError(), pProgID(strProcedure)
Else 'got DC handle
'so proceed to get the text metrics
If GetTextMetrics(lngReturn, cdsTmp) = 0 Then
Err.Raise GetLastError(), pProgID(strProcedure)
Else
MaxTextWidth = cdsTmp.tmMaxCharWidth * lngNofCharacters * Screen.TwipsPerPixelX
End If
End If
Exit Function
errHandler:
Dim lngErrNumber As Long: lngErrNumber = Err.Number
Dim strErrSource As String: strErrSource = Err.Source
Dim strErrDescription As String: strErrDescription = Err.Description
Dim strErrHelpFile As String: strErrHelpFile = Err.HelpFile
Dim strErrHelpContext As String: strErrHelpContext = Err.HelpContext
Select Case HandleErrors
Case bbRetry
Resume
Case bbIgnore
Resume Next
Case Else
Err.Raise lngErrNumber, strErrSource, strErrDescription
End Select
End Function
Why doesn't it work?