Hallo Backbox,
vielen Dank für deine Antwort. Du gibst mir Hoffnung. Leider ist das vielleicht etwas unter gegangen, aber der Code im ersten Post war schon die von mir - so gut es geht - bearbeitete Version. Der Origianalcode sieht so aus (siehe unten).
1. Bezüglich der einen gdi32.dll: Muss die nicht noch "eingebunden" werden? Ich hatte mir dafür folgenden Code überlegt gehabt:
RegServe App.Path & "\" & gdi32.dll, True App.Path zeigt doch vermutlich in C:\Windows\System32\ wo ich diese dll vermute, richtig?
2. Ich habe die Vermutung bei der Zeile:
GetFontUnicodeRanges(hdc, glyphSet) handelt es sich um eine Rekursion??? Wie geht das in VBA? So:
GetFontUnicodeRanges = GetFontUnicodeRanges(hdc, glyphSet) 3. Ich bin mir nicht sicher was du mit Pointer in diesem Code meinst?
4. Die zwei APIs die du ansprichst habe ich auch noch nicht verstanden was ich damit machen muss.
Hier der original Code (ohne Veränderungen) in VB.NET
<DllImport("gdi32.dll")> _
Public Shared Function GetFontUnicodeRanges(ByVal hds As IntPtr, ByVal lpgs As _
IntPtr) As UInteger
End Function
<DllImport("gdi32.dll")> _
Public Shared Function SelectObject(ByVal hDc As IntPtr, ByVal hObject As _
IntPtr) As IntPtr
End Function
Public Structure FontRange
Public Low As UInt16
Public High As UInt16
End Structure
Public Function GetUnicodeRangesForFont(ByVal font As Font) As List(Of _
FontRange)
Dim g As Graphics
Dim hdc, hFont, old, glyphSet As IntPtr
Dim size As UInteger
Dim fontRanges As List(Of FontRange)
Dim count As Integer
g = Graphics.FromHwnd(IntPtr.Zero)
hdc = g.GetHdc()
hFont = font.ToHfont()
old = SelectObject(hdc, hFont)
size = GetFontUnicodeRanges(hdc, IntPtr.Zero)
glyphSet = Marshal.AllocHGlobal(CInt(size))
GetFontUnicodeRanges(hdc, glyphSet)
fontRanges = New List(Of FontRange)
count = Marshal.ReadInt32(glyphSet, 12)
For i As Integer = 0 To count - 1
Dim range As FontRange = New FontRange
range.Low = Unsign(Marshal.ReadInt16(glyphSet, 16 + (i * 4)))
range.High = range.Low + Unsign(Marshal.ReadInt16(glyphSet, 18 + (i * 4)) - _
1)
fontRanges.Add(range)
Next
SelectObject(hdc, old)
Marshal.FreeHGlobal(glyphSet)
g.ReleaseHdc(hdc)
g.Dispose()
Return fontRanges
End Function
Public Function CheckIfCharInFont(ByVal character As Char, ByVal font As Font) _
As Boolean
Dim intval As UInt16 = Convert.ToUInt16(character)
Dim ranges As List(Of FontRange) = GetUnicodeRangesForFont(font)
Dim isCharacterPresent As Boolean = False
For Each range In ranges
If intval >= range.Low And intval <= range.High Then
isCharacterPresent = True
Exit For
End If
Next range
Return isCharacterPresent
End Function
Protected Function Unsign(ByVal Input As Int16) As UInt16
If Input > -1 Then
Return CType(Input, UInt16)
Else
Return UInt16.MaxValue - (Not Input)
End If
End Function Vielen Dank für deine Hilfe, ich hoffe wir bekommen das zusammen hin. |