Textbreite mit GetTextExtentPoint bestimmen
Andreas
ich habe per Suchmaschine eine Funktion gefunden, mit der es möglich ist, die Breite eines Strings zu bestimmen:
Private Type SIZE
cx As Long
cy As Long
End Type
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPointA" (ByVal _
hDC As Long, ByVal lpszStr As String, ByVal cchString As Long, lpSize As SIZE) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Public Function GetTxtPxLen(ByVal sTxt As String) As Long
Dim hWnd As Long
Dim hDC As Long
Dim sz As SIZE
hWnd = GetForegroundWindow()
If hWnd Then
hDC = GetDC(hWnd)
If hDC Then
GetTextExtentPoint32 hDC, sTxt, Len(sTxt), sz
ReleaseDC hWnd, hDC
GetTxtPxLen = sz.cx
End If
End If
End Function
Ich wüsste nun sehr gern, welcher Font von Funktion GetTextExtentPoint32 bei der Berechnung zugrunde gelegt wird. Ich konnte hierzu nur folgende Information finden:The GetTextExtentPoint32 function uses the currently selected font to compute the dimensions of the string.
Kann mir jemand verraten, wie ich mir den "currently selected font" anzeigen lassen kann? Optimal wäre es, wenn ich ihn auch noch verändern könnte.Grüße
A.M.