_GDIPlus_GraphicsDrawStringEx / Buchstaben zentrieren??

  • Hallo,

    in dieser GUI werden installierte Schriftarten angezeigt, aber ich bekomms nicht hin das die versch. Buchstaben in den versch. Schriftarten im Ausgabefenster zentriert sind!

    Wie bekomme ich jeden Buchstaben in die Mitte des Fensters??

    *Zeile mit _GDIPlus_RectFCreate!?!

    Spoiler anzeigen
    [autoit]

    #include <File.au3>
    #include <Array.au3>
    #include <RegFunc.au3>
    #include <ListviewConstants.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>
    #include <UpDownConstants.au3>
    #include <EditConstants.au3>
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    Opt("GUIOnEventMode", 1)
    ;Data
    $dString = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'
    $aString = StringSplit($dString, ',')
    Local $data[2][$aString[0] + 1]
    For $i = 1 to $aString[0]
    $data[0][$i] = $aString[$i]
    $data[1][$i] = $i
    Next
    $data[0][0] = (UBound($data, 2) - 1)
    ;_ArrayDisplay($data, -1, -1, 1)
    $cDataCount = 1 ;Letter Stellenzähler
    $capi = 0 ;Gross- und Kleinschreibung
    $FontList = _FileListToArray(@WindowsDir & '\Fonts', '*.ttf', 1);Schriftarten aus Windows Fonts Ordner holen
    If @error = 1 Then
    MsgBox(0, "", "No Folders Found.")
    cleanup()
    Exit
    EndIf
    If @error = 4 Then
    MsgBox(0, "", "No Files Found.")
    cleanup()
    Exit
    EndIf
    $var = _GetRegValues('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts');Schriftartennamen aus Windows Registry holen
    Dim $aItems[($FontList[0] + 1)]
    $x = 1
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
    ;Arrays anzeigen
    ;~ _ArrayDisplay($FontList, "$FileList")
    ;~ _ArrayDisplay($var)
    ;GUI erstellen
    $msg = GUICreate("Installierte Schriftarten", 400, 500)
    $listview = GUICtrlCreateListView("Nr.|Datei|Name", 10, 10, 380, 150, $LVS_SINGLESEL)
    $button = GUICtrlCreateButton("OK", 20, 170, 70, 20)
    $gWin = GUICtrlCreateGraphic(20, 200, 100, 100)
    $iLetter = GUICtrlCreateInput ("a", 100, 170, 20, 20, $ES_CENTER)
    GUICtrlCreateLabel('Schriftgrösse: ', 140, 170, 65, 20)
    $SchriftG = GUICtrlCreateInput('12', 210, 170, 36, 20)
    $updwnSGR = GUICtrlCreateUpdown($SchriftG)
    $gross = GUICtrlCreateButton('', 121, 170, 10, 10)
    $klein = GUICtrlCreateButton('', 121, 180, 10, 10)
    $bUp = GUICtrlCreateButton('Up', 121, 200, 24, 50)
    $bDown = GUICtrlCreateButton('Dwn', 121, 250, 24, 50)
    GUICtrlSetBkColor($gWin, 0xffffff)
    GUICtrlSetBkColor($klein, 0x00ff00)
    GUICtrlSetBkColor($gross, 0x8B0000)
    GUICtrlSetColor($gWin, 0)
    GUICtrlSetLimit($iLetter, 1)
    GUICtrlSetLimit($listview, 1)
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUICtrlSetOnEvent($button, "button")
    GUICtrlSetOnEvent($bUp, "UP")
    GUICtrlSetOnEvent($bDown, "DOWN")
    GUICtrlSetOnEvent($gross, "gross")
    GUICtrlSetOnEvent($klein, "klein")
    GUICtrlSetOnEvent($updwnSGR, "SchriftGR")
    _GUICtrlListView_SetSelectionMark($listview, 1)
    $sTrim = _GUICtrlListView_GetSelectionMark($listview)
    ;GUI Liste schreiben
    For $a = 1 To UBound($var)
    If StringRight($var[$a - 1][2], 3) = 'ttf' Then
    $aItems[$x] = GUICtrlCreateListViewItem($x & '|' & $var[$a - 1][2] & '|' & $var[$a - 1][0], $listview)
    GUICtrlSetOnEvent($aItems[$x], "HandleClicks")
    $x = $x + 1
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Drawing()

    [/autoit] [autoit][/autoit] [autoit]

    ;GUI loop
    While 1
    $rAktList = GUICtrlRead($listview)
    WEnd
    ;Funktionen
    ;SpecialEvents
    Func SpecialEvents()
    Select
    Case @GUI_CtrlId = $GUI_EVENT_CLOSE
    cleanup()
    Exit
    EndSelect
    EndFunc
    ;HandleClicks
    Func HandleClicks()
    $aktSel = GUICtrlRead(GUICtrlRead($listview))
    $aList = StringSplit($aktSel,'|')
    $sTrim = StringTrimRight($aList[3], 11)
    Drawing()
    EndFunc
    ;button()
    Func button()
    $rInput = GUICtrlRead($iLetter)
    MsgBox(0, 'Schriftart', GUICtrlRead(GUICtrlRead($listview)), 2)
    Drawing()
    EndFunc
    ;UP()
    Func UP()
    If $cDataCount < $aString[0] Then
    $cDataCount = $cDataCount + 1
    EndIf
    If $capi = 0 Then
    $new = StringLower($aString[$cDataCount])
    Else
    $new = StringUpper($aString[$cDataCount])
    EndIf
    GUICtrlSetData($iLetter, $new)
    Drawing()
    EndFunc
    ;DOWN()
    Func DOWN()
    If $cDataCount >= 2 Then
    $cDataCount = $cDataCount - 1
    EndIf
    If $capi = 1 Then
    gross()
    EndIf
    If $capi = 0 Then
    $new = StringLower($aString[$cDataCount])
    Else
    $new = StringUpper($aString[$cDataCount])
    EndIf
    GUICtrlSetData($iLetter, $new)
    Drawing()
    EndFunc
    Func gross()
    $capi = 1
    $rInput = GUICtrlRead($iLetter)
    $new = StringUpper($rInput)
    GUICtrlSetData($iLetter, $new)
    GUICtrlSetBkColor($gross, 0x00ff00)
    GUICtrlSetBkColor($klein, 0x8B0000)
    Drawing()
    EndFunc
    Func klein()
    $capi = 0
    $rInput = GUICtrlRead($iLetter)
    $new = StringLower($rInput)
    GUICtrlSetData($iLetter, $new)
    GUICtrlSetBkColor($klein, 0x00ff00)
    GUICtrlSetBkColor($gross, 0x8B0000)
    Drawing()
    EndFunc
    Func SchriftGR()
    $sgr = GUICtrlRead($SchriftG)
    If $sgr <= 2 Then
    GUICtrlSetData($SchriftG, 2)
    EndIf
    If $sgr >= 80 Then
    GUICtrlSetData($SchriftG, 80)
    EndIf
    Drawing()
    EndFunc
    Func Drawing()
    GUICtrlSetColor($gWin, 0)
    $rInput = GUICtrlRead($iLetter)
    $sgr = GUICtrlRead($SchriftG)
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($msg)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    $hFormat = _GDIPlus_StringFormatCreate()
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    $hFamily = _GDIPlus_FontFamilyCreate($sTrim)
    $hFont = _GDIPlus_FontCreate($hFamily, $sgr, 0, 2)
    $tLayout = _GDIPlus_RectFCreate(0, 50 - ($sgr / 2), 100, 100)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $rInput, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $rInput, $hFont, $aInfo[0], $hFormat, $hBrush)
    EndFunc
    ; Clean up resources
    Func cleanup()
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    EndFunc
    ;Ende
    cleanup()
    Exit

    [/autoit]

    Wer sonst noch Tipps zur Verbesserung hat, her damit! :D

    Danke!

    Edit: Hab jetzt die Zeilen

    $tLayout = _GDIPlus_RectFCreate(0, 50 - ($sgr / 2), 100, 100)

    _GDIPlus_StringFormatSetAlign($hFormat, 1)

    eingefügt, aber nicht alle Schriftarten passen!! Ist das normal??

    3 Mal editiert, zuletzt von Morrison (5. Februar 2012 um 18:52)

  • Die Breite und Höhe eines Strings in einer bestimmten Schriftart kannst du mit

    [autoit]

    _GDIPlus_GraphicsMeasureString

    [/autoit]

    messen (Daten sind in einem DLLStruct im ersten Element des zurückgegebenen Arrays). Dann könntest du die Position so errechnen:
    X = Fensterbreite / 2 - Stringbreite / 2
    Y = Fensterhöhe / 2 - Stringhöhe / 2
    Und dann kannst du ein neues Layout mit der RectF Funktion erstellen.

    In der Hilfe müsste ein Beispiel zu der Funktion sein, und Oscar hat glaube ich auch mal ein Beispiel dafür geschrieben.
    Wenn du den Text mit FormatSetAlign zentrierst, dann musst du das Rechteck auch am linken Rand des Fensters lassen, ansonsten wird der Text irgendwo anders zentriert ;).

  • Hallo,

    danke für die Antwort! Das mit dem berechnen habbich nicht hinbekommen! ?( Vllt. nen Beispiel dazu??

    Hab in diesem Forum was von _WinAPI_GetTextExtentPoint32 gefunden. Scheint der richtige Befehl zu sein, oder??

    Hab jetzt

    $foo = _WinAPI_GetTextExtentPoint32($msg, $rInput)
    $x = DllStructGetData($foo,"X")
    $y = DllStructGetData($foo,"Y")
    ConsoleWrite($x & @TAB & $y & @CRLF)

    hinzugefügt, bekomm als Ergebnis aber nur Nullen!! Wieso??

    Tja, bin halt Anfänger! :S

  • Hiho!

    Also jetzt ist des Problem mit dem "$tRect = DllStructCreate($tagRECT)"!!

    Leider stimmen die Abmessungen nicht, vllt. kennt sich da jemand mit aus..mit _WinAPI_GetTextExtentPoint32 usw.

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <EditConstants.au3>
    #include <File.au3>
    #include <Fontconstants.au3>
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListviewConstants.au3>
    #include <ProgressConstants.au3>
    #include <RegFunc.au3>
    #include <StaticConstants.au3>
    #include <UpDownConstants.au3>
    #include <WindowsConstants.au3>
    Opt("GUIOnEventMode", 1)
    ;OnAutoItExitRegister('cleanup')

    [/autoit] [autoit][/autoit] [autoit]

    ;Data
    $dString = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ä,ö,ü,'
    $aString = StringSplit($dString, ',')
    Local $data[3][$aString[0] + 1]
    For $i = 1 To $aString[0]
    $data[0][$i] = $i
    $data[1][$i] = StringUpper($aString[$i])
    $data[2][$i] = StringLower($aString[$i])
    Next
    $data[0][0] = (UBound($data, 2) - 1)
    ;_ArrayDisplay($data, -1, -1, 1)
    $cDataCount = 1 ;Letter Stellenzähler
    $capi = 0 ;Gross- und Kleinschreibung
    $FontList = _FileListToArray(@WindowsDir & '\Fonts', '*.ttf', 1);Schriftarten aus Windows Fonts Ordner holen
    If @error = 1 Then
    MsgBox(0, "", "No Folders Found.")
    cleanup()
    Exit
    EndIf
    If @error = 4 Then
    MsgBox(0, "", "No Files Found.")
    cleanup()
    Exit
    EndIf
    $var = _GetRegValues('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts');Schriftartennamen aus Windows Registry holen
    Dim $aItems[($FontList[0] + 1)]
    $x = 1
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=C:\Users\IBM\Desktop\Form1.kxf
    $msg = GUICreate("Schriftarten Tool", 587, 245, 215, 124)
    $MenuItem2 = GUICtrlCreateMenu("Datei")
    $MenuItem4 = GUICtrlCreateMenuItem("Optionen", $MenuItem2)
    $MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem2)
    $MenuItem1 = GUICtrlCreateMenu("Hilfe")
    $listview = GUICtrlCreateListView("Nr.|Datei|Name", 277, 12, 305, 158, -1, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE,$LVS_EX_FULLROWSELECT))
    $gWin1 = GUICtrlCreateGraphic(11, 70, 100, 100, $SS_WHITERECT)
    $gWin2 = GUICtrlCreateGraphic(171, 70, 100, 100, $SS_WHITERECT)
    $bUp = GUICtrlCreateButton("Up", 123, 70, 35, 35, -1, $WS_EX_CLIENTEDGE)
    $bDown = GUICtrlCreateButton("Dwn", 123, 135, 35, 35, -1, $WS_EX_CLIENTEDGE)
    $SchriftG = GUICtrlCreateInput('32', 123, 110, 35, 20)
    $updwnSGR = GUICtrlCreateUpdown($SchriftG)
    $bStart = GUICtrlCreateButton("Start", 25, 190, 80, 25, -1, $WS_EX_STATICEDGE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $bAbbruch = GUICtrlCreateButton("Abbruch", 177, 190, 80, 25, -1, $WS_EX_STATICEDGE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Progress1 = GUICtrlCreateProgress(21, 175, 240, 10, -1, $WS_EX_STATICEDGE)
    $bFontDir = GUICtrlCreateButton(@WindowsDir & '\Fonts', 61, 2, 160, 20)
    $Combo1 = GUICtrlCreateCombo("", 41, 27, 200, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    $bAllData = GUICtrlCreateButton("Alle Daten", 330, 180, 190, 25)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    _GUICtrlListView_SetColumnWidth($listview, 0, 28)
    _GUICtrlListView_SetColumnWidth($listview, 1, 40)
    _GUICtrlListView_SetColumnWidth($listview, 2, 130)
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUICtrlSetOnEvent($bStart, "button")
    GUICtrlSetOnEvent($bUp, "UP")
    GUICtrlSetOnEvent($bDown, "DOWN")

    [/autoit] [autoit][/autoit] [autoit]

    ;GUI Liste schreiben
    For $a = 1 To UBound($var)
    If StringRight($var[$a - 1][2], 3) = 'ttf' Then
    If StringInStr($var[$a - 1][0], 'Bold', 1) = False And StringInStr($var[$a - 1][0], 'Italic', 1) = False And StringInStr($var[$a - 1][0], 'MT Extra', 1) = False Then
    $aItems[$x] = GUICtrlCreateListViewItem($x & '|' & $var[$a - 1][2] & '|' & $var[$a - 1][0], $listview)
    GUICtrlSetOnEvent($aItems[$x], "HandleClicks")
    $x = $x + 1
    EndIf
    EndIf
    Next
    _GUICtrlListView_SetSelectionMark($listview, 0)
    $sTrim = _GUICtrlListView_GetSelectionMark($listview)
    _GUICtrlListView_ClickItem($listview, 0, "left", False, 1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $rAktList = GUICtrlRead($listview)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ;Funktionen
    ;SpecialEvents
    Func SpecialEvents()
    Select
    Case @GUI_CtrlId = $GUI_EVENT_CLOSE
    cleanup()
    Exit
    EndSelect
    EndFunc ;==>SpecialEvents
    ;HandleClicks
    Func HandleClicks()
    $aktSel = GUICtrlRead(GUICtrlRead($listview))
    $aList = StringSplit($aktSel, '|')
    $sTrim = StringTrimRight($aList[3], 11)
    Drawing()
    EndFunc ;==>HandleClicks
    ;button()
    Func button()
    ;$rInput1 = GUICtrlRead($iLetter)
    MsgBox(0, 'Schriftart', GUICtrlRead(GUICtrlRead($listview)), 2)
    Drawing()
    EndFunc ;==>button
    ;UP()
    Func UP()
    If $cDataCount < $aString[0] Then
    $cDataCount = $cDataCount + 1
    EndIf
    ;GUICtrlSetData($iLetter, $new)
    Drawing()
    EndFunc ;==>UP
    ;DOWN()
    Func DOWN()
    If $cDataCount >= 2 Then
    $cDataCount = $cDataCount - 1
    EndIf
    ;GUICtrlSetData($iLetter, $new)
    Drawing()
    EndFunc ;==>DOWN
    Func SchriftGR()
    $sgr = GUICtrlRead($SchriftG)
    If $sgr <= 8 Then
    GUICtrlSetData($SchriftG, 8)
    EndIf
    If $sgr >= 60 Then
    GUICtrlSetData($SchriftG, 60)
    EndIf
    Drawing()
    EndFunc ;==>SchriftGR
    Func Drawing()
    ;~ GUICtrlSetColor($gWin1, 0)
    ;~ $rInput1 = 'A' ;GUICtrlRead($iLetter)
    ;~ $sgr = GUICtrlRead($SchriftG)
    ;~ _GDIPlus_Startup()
    ;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND($msg)
    ;~ $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    ;~ $hFormat = _GDIPlus_StringFormatCreate()
    ;~ $hFamily = _GDIPlus_FontFamilyCreate($sTrim)
    ;~ $hFont = _GDIPlus_FontCreate($hFamily, $sgr, 0, 2)
    ;~ $tLayout = _GDIPlus_RectFCreate(0, 0, 100, 100)
    ;~ $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $rInput1, $hFont, $tLayout, $hFormat)
    ;~ $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    ;~ $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    ;~ cleanup()
    ;~ _GDIPlus_Startup()
    ;~ $hWind = WinGetHandle($oForm)
    ;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWind)
    ;~ $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic)
    ;~ $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    ;~ _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF)
    ;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND($msg)
    ;~ $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    ;~ $hFormat = _GDIPlus_StringFormatCreate()
    ;~ $hFamily = _GDIPlus_FontFamilyCreate($sTrim)
    ;~ $hFont = _GDIPlus_FontCreate($hFamily, $sgr, 0, 2)
    ;~ $tLayout = _GDIPlus_RectFCreate(50 - ($iWidth / 2), 50 - ($iHeight / 2), 100, 100)
    ;~ $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $rInput1, $hFont, $tLayout, $hFormat)
    ;~ _GDIPlus_GraphicsDrawStringEx($hGraphic, $rInput1, $hFont, $aInfo[0], $hFormat, $hBrush)

    [/autoit] [autoit][/autoit] [autoit]

    Local $iRectWidth, $iRectHeight, $aCtrlPos1
    GUICtrlSetColor($gWin1, 0)
    GUICtrlSetColor($gWin2, 0)
    $rInput = 'A' ;GUICtrlRead($iLetter)
    $rInput1 = StringUpper($rInput)
    $rInput2 = StringLower($rInput)
    $sgr = GUICtrlRead($SchriftG)
    ; Größe des Graphic-Controls ermitteln (Noch 100x100, aber wer weiß, wann sich das ändert)
    $aCtrlPos1 = ControlGetPos($msg,'',$gWin1)
    $aCtrlPos2 = ControlGetPos($msg,'',$gWin2)
    $iRectWidth = $aCtrlPos1[2]
    $iRectHeight = $aCtrlPos1[3]
    ; DC vom Graphics-Control holen
    $hDC1 = _WinAPI_GetDC(GUICtrlGetHandle($gWin1))
    $hDC2 = _WinAPI_GetDC(GUICtrlGetHandle($gWin2))
    ; Font erstellen
    ;$iDeviceCapY = _WinAPI_GetDeviceCaps($hDC1, $__WINAPICONSTANT_LOGPIXELSX)
    ;MsgBox(0, '', $iDeviceCapY)
    $hFont = _WinAPI_CreateFont($sgr, 0, 0, 0, $FW_NORMAL, False, False, False _
    , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $sTrim)
    ; Font mit DC verbinden
    _WinAPI_SelectObject($hDC1, $hFont)
    _WinAPI_SelectObject($hDC2, $hFont)
    ; Textgröße ermitteln
    $tPoint1 = _WinAPI_GetTextExtentPoint32($hDC1, $rInput1)
    $tPoint2 = _WinAPI_GetTextExtentPoint32($hDC2, $rInput2)
    $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - (DllStructGetData($tPoint1, 'x') / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - (DllStructGetData($tPoint1, 'y') / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint1, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint1, 'y'))
    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - (DllStructGetData($tPoint2, 'x') / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - (DllStructGetData($tPoint2, 'y') / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint2, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint2, 'y'))
    ; Text auf Graphics-Control zeichnen
    _WinAPI_DrawText($hDC1,$rInput1, $tRect, BitOR($DT_VCENTER, $DT_CENTER))
    _WinAPI_DrawText($hDC2,$rInput2, $tRect, BitOR($DT_VCENTER, $DT_CENTER))
    ; DC wieder freigeben, Font löschen & von Strukturen reservierten Speicher freigeben.
    _WinAPI_ReleaseDC(GUICtrlGetHandle($gWin1), $hDC1)
    _WinAPI_ReleaseDC(GUICtrlGetHandle($gWin2), $hDC2)
    _WinAPI_DeleteObject($hFont)
    $tPoint1 = 0
    $tPoint2 = 0
    $tRect = 0
    EndFunc ;==>Drawing
    ; Clean up resources
    Func cleanup()
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    EndFunc ;==>cleanup
    ;Ende
    cleanup()
    Exit

    [/autoit]
  • _WinAPI_GetTextExtentPoint32 geht nur mit GDI-Funktionen, aber nicht mit GDIPlus.

    Measurestring ist nicht immer ganz genau, deshalb verwende ich lieber Pfade, um einen Text exakt abzumessen:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("MustDeclareVars", 1)
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGui = GUICreate("Test", 320, 240)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    _GDIPlus_Startup()
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics(320, 240, $hGraphics)
    Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
    _GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
    Global $hPen = _GDIPlus_PenCreate(0xFF00FF00)
    Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
    GUIRegisterMsg($WM_PAINT, "WM_PAINT")
    GUIRegisterMsg($WM_ERASEBKGND, "WM_PAINT")
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawLine($hGfxBuffer, 160, 0, 160, 240, $hPen)

    [/autoit] [autoit][/autoit] [autoit]

    _Zentriere("Test", 160, 120)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Zentriere($sString, $iX, $iY, $fSize = 70, $sFont = "Arial")
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]

    [/autoit] [autoit][/autoit] [autoit]

    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local $tBounds = _GDIPlus_RectFCreate(0, 0, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    DllCall($ghGDIPDll, "uint", "GdipAddPathString", "hwnd", $hPath, "wstr", $sString, "int", -1, "hwnd", $hFamily, "int", 0, "float", $fSize, "ptr", DllStructGetPtr($tLayout), "hwnd", $hFormat)
    DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tBounds), "hwnd", 0, "hwnd", 0)

    [/autoit] [autoit][/autoit] [autoit]

    Local $fRectX = DllStructGetData($tBounds, "X")
    Local $fRectY = DllStructGetData($tBounds, "Y")
    Local $fRectW = DllStructGetData($tBounds, "Width")
    Local $fRectH = DllStructGetData($tBounds, "Height")

    [/autoit] [autoit][/autoit] [autoit]

    Local $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix, -$fRectX - $fRectW / 2 + $iX, -$fRectY - $fRectH / 2 + $iY)
    DllCall($ghGDIPDll, "uint", "GdipTransformPath", "hwnd", $hPath, "hwnd", $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)

    [/autoit] [autoit][/autoit] [autoit]

    DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hGfxBuffer, "hwnd", $hBrush, "hwnd", $hPath)

    [/autoit] [autoit][/autoit] [autoit]

    DllCall($ghGDIPDll, "int", "GdipDrawRectangle", "handle", $hGfxBuffer, "handle", $hPen, "float", $iX - $fRectW / 2, "float", $iY - $fRectH / 2, "float", $fRectW, "float", $fRectH)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)

    [/autoit] [autoit][/autoit] [autoit]

    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)
    EndFunc ;==>_Zentriere

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_PAINT

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    E

  • Hallo,

    hab versucht jetzt das "$tagRECT" neu zu berechnen, das ist aber trotzdem nicht mittig!! :huh:

    ..und weiss jemand wie ich des ganze schneller berechnen kann???

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <EditConstants.au3>
    #include <File.au3>
    #include <Fontconstants.au3>
    #include <GDIPlus.au3>
    #include <GuiButton.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListviewConstants.au3>
    #include <ProgressConstants.au3>
    #include <RegFunc.au3>
    #include <StaticConstants.au3>
    #include <UpDownConstants.au3>
    #include <WindowsConstants.au3>
    Opt("GUIOnEventMode", 1)
    Opt("PixelCoordMode", 0)
    ;Data
    $dString = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ä,ö,ü'
    $aString = StringSplit($dString, ',')
    Local $data[3][$aString[0] + 1]
    Local $rLinks, $rRechts, $rOben, $rUnten, $rWidth, $rHeight
    For $i = 1 To $aString[0]
    $data[0][$i] = $i
    $data[1][$i] = StringUpper($aString[$i])
    $data[2][$i] = StringLower($aString[$i])
    Next
    $cDataCount = 1 ;Letter Stellenzähler
    $data[0][0] = (UBound($data, 2) - 1)
    ;Fonts
    $FontList = _FileListToArray(@WindowsDir & '\Fonts', '*.ttf', 1);Schriftarten aus Windows Fonts Ordner holen
    $var = _GetRegValues('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts');Schriftartennamen aus Windows Registry holen
    Dim $aItems[($FontList[0] + 1)]
    $x = 1
    #region ### START Koda GUI section ### Form=C:\Users\IBM\Desktop\AU3_OCR_new\Form1.kxf
    $msg = GUICreate("Form1", 620, 245, 215, 124)
    $Datei = GUICtrlCreateMenu("&Datei")
    $MenuItem1 = GUICtrlCreateMenuItem("Optionen" & @TAB & "", $Datei)
    $MenuItem2 = GUICtrlCreateMenuItem("Exit" & @TAB & "", $Datei)
    $Hilfe = GUICtrlCreateMenu("&Hilfe")
    $listview = GUICtrlCreateListView("Nr.|Datei|Name", 277, 12, 335, 170)
    $gWin1 = GUICtrlCreateGraphic(11, 66, 100, 100, $SS_WHITERECT)
    $gWin2 = GUICtrlCreateGraphic(171, 66, 100, 100, $SS_WHITERECT)
    $SchriftG = GUICtrlCreateInput('32', 123, 106, 35, 20)
    $updwnSGR = GUICtrlCreateUpdown($SchriftG)
    $bUp = GUICtrlCreateButton("Up", 123, 66, 35, 35, -1, $WS_EX_CLIENTEDGE)
    $bDown = GUICtrlCreateButton("Dwn", 123, 131, 35, 35, -1, $WS_EX_CLIENTEDGE)
    $bStart = GUICtrlCreateButton("Start", 26, 190, 80, 25, -1, $WS_EX_STATICEDGE)
    $bAbbruch = GUICtrlCreateButton("Abbruch", 176, 190, 80, 25, -1, $WS_EX_STATICEDGE)
    $bDaten = GUICtrlCreateButton("Alle Daten", 352, 188, 190, 30)
    $Progress1 = GUICtrlCreateProgress(21, 172, 240, 10, -1, $WS_EX_STATICEDGE)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###
    _GUICtrlListView_SetColumnWidth($listview, 0, 28)
    _GUICtrlListView_SetColumnWidth($listview, 1, 40)
    _GUICtrlListView_SetColumnWidth($listview, 2, 180)
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUICtrlSetOnEvent($bStart, "button")
    GUICtrlSetOnEvent($bUp, "UP")
    GUICtrlSetOnEvent($bDown, "DOWN")
    GUICtrlSetOnEvent($listview, "HandleClicks")
    GUICtrlSetOnEvent($updwnSGR, "SchriftGR")
    ;GUI Liste schreiben
    For $a = 1 To UBound($var)
    If StringRight($var[$a - 1][2], 3) = 'ttf' Then
    If StringInStr($var[$a - 1][0], 'Bold', 1) = False And StringInStr($var[$a - 1][0], 'Italic', 1) = False _
    And StringInStr($var[$a - 1][0], 'MT Extra', 1) = False Then
    $nName = StringReplace($var[$a - 1][0], '(TrueType)', '', 1)
    $aItems[$x] = GUICtrlCreateListViewItem($x & '|' & $var[$a - 1][2] & '|' & $nName, $listview)
    GUICtrlSetOnEvent($aItems[$x], "HandleClicks")
    $x = $x + 1
    EndIf
    EndIf
    Next
    _GUICtrlListView_SetSelectionMark($listview, 0)
    $sTrim = _GUICtrlListView_GetSelectionMark($listview)
    _GUICtrlListView_ClickItem($listview, 0, "left", False, 1)
    While 1
    $rAktList = GUICtrlRead($listview)
    $sgr = GUICtrlRead($SchriftG)
    WEnd
    ;Funktionen
    ;SpecialEvents
    Func SpecialEvents()
    Select
    Case @GUI_CtrlId = $GUI_EVENT_CLOSE
    cleanup()
    Exit
    EndSelect
    EndFunc ;==>SpecialEvents
    ;HandleClicks
    Func HandleClicks()
    $aktSel = GUICtrlRead(GUICtrlRead($listview))
    $aList = StringSplit($aktSel, '|')
    $sTrim = StringTrimRight($aList[3], 1)
    ;_ArrayDisplay($aList)
    Drawing()
    EndFunc ;==>HandleClicks
    ;button()
    Func button()
    ;$rInput1 = GUICtrlRead($iLetter)
    MsgBox(0, 'Schriftart', GUICtrlRead(GUICtrlRead($listview)), 2)
    Drawing()
    EndFunc ;==>button
    ;UP()
    Func UP()
    If $cDataCount < $aString[0] Then
    $cDataCount = $cDataCount + 1
    EndIf
    Drawing()
    EndFunc ;==>UP
    ;DOWN()
    Func DOWN()
    If $cDataCount >= 2 Then
    $cDataCount = $cDataCount - 1
    EndIf
    Drawing()
    EndFunc ;==>DOWN
    Func SchriftGR()
    $sgr = GUICtrlRead($SchriftG)
    If $sgr <= 8 Then
    GUICtrlSetData($SchriftG, 8)
    EndIf
    If $sgr >= 99 Then
    GUICtrlSetData($SchriftG, 99)
    EndIf
    Drawing()
    EndFunc ;==>SchriftGR
    Func Drawing()
    Local $iRectWidth, $iRectHeight, $aCtrlPos1
    GUICtrlSetColor($gWin1, 0)
    GUICtrlSetColor($gWin2, 0)
    $rInput = $aString[$cDataCount]
    $rInput1 = StringUpper($rInput)
    $rInput2 = StringLower($rInput)
    $sgr = GUICtrlRead($SchriftG)
    ; Größe des Graphic-Controls ermitteln (Noch 100x100, aber wer weiß, wann sich das ändert)
    $aCtrlPos1 = ControlGetPos($msg, '', $gWin1)
    $aCtrlPos2 = ControlGetPos($msg, '', $gWin2)
    $iRectWidth = $aCtrlPos1[2]
    $iRectHeight = $aCtrlPos1[3]
    ; DC vom Graphics-Control holen
    $hDC1 = _WinAPI_GetDC(GUICtrlGetHandle($gWin1))
    $hDC2 = _WinAPI_GetDC(GUICtrlGetHandle($gWin2))
    ; Font erstellen
    ;$iDeviceCapY = _WinAPI_GetDeviceCaps($hDC1, $__WINAPICONSTANT_LOGPIXELSX)
    ;MsgBox(0, '', $iDeviceCapY)
    $hFont = _WinAPI_CreateFont($sgr, 0, 0, 0, $FW_NORMAL, False, False, False _
    , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $sTrim)
    ; Font mit DC verbinden
    _WinAPI_SelectObject($hDC1, $hFont)
    _WinAPI_SelectObject($hDC2, $hFont)
    ;Font zeichnen
    $tPoint1 = _WinAPI_GetTextExtentPoint32($hDC1, $rInput1)
    $tPoint2 = _WinAPI_GetTextExtentPoint32($hDC2, $rInput2)
    $tRect = DllStructCreate($tagRECT)
    ;~ $tRect1 = _WinAPI_DrawText($hDC1, $rInput1, $tRect, $DT_CALCRECT)
    ;~ $tRect2 = _WinAPI_DrawText($hDC1, $rInput1, $tRect, $DT_CALCRECT)
    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - (DllStructGetData($tPoint1, 'x') / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - (DllStructGetData($tPoint1, 'y') / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint1, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint1, 'y'))
    ; Text auf Graphics-Control zeichnen
    _WinAPI_DrawText($hDC1, $rInput1, $tRect, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
    _WinAPI_DrawText($hDC2, $rInput2, $tRect, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))

    [/autoit] [autoit][/autoit] [autoit]

    GetRect($gWin1)
    ;~ MsgBox(0, '', 'Links: ' & $rLinks & @CRLF & 'Rechts: ' & $rRechts & @CRLF & 'Oben: ' & $rOben & @CRLF & 'Unten: ' & $rUnten _
    ;~ & @CRLF & 'Breite: ' & $rWidth & @CRLF & 'Höhe: ' & $rHeight)
    ;~
    $tRect1 = DllStructCreate($tagRECT)
    DllStructSetData($tRect1, 'left', 50 - ($rWidth / 2))
    DllStructSetData($tRect1, 'top', 50 - ($rHeight / 2))
    DllStructSetData($tRect1, 'right', 50 + ($rWidth / 2))
    DllStructSetData($tRect1, 'bottom', 50 + ($rHeight / 2))
    GUICtrlSetColor($gWin1, 0)
    _WinAPI_DrawText($hDC1, $rInput1, $tRect1, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))
    GetRect($gWin2)
    ;~ MsgBox(0, '', 'Links: ' & $rLinks & @CRLF & 'Rechts: ' & $rRechts & @CRLF & 'Oben: ' & $rOben & @CRLF & 'Unten: ' & $rUnten _
    ;~ & @CRLF & 'Breite: ' & $rWidth & @CRLF & 'Höhe: ' & $rHeight)
    $tRect2 = DllStructCreate($tagRECT)
    DllStructSetData($tRect2, 'left', 50 - ($rWidth / 2))
    DllStructSetData($tRect2, 'top', 50 - ($rHeight / 2))
    DllStructSetData($tRect2, 'right', 50 + ($rWidth / 2))
    DllStructSetData($tRect2, 'bottom', 50 + ($rHeight / 2))
    GUICtrlSetColor($gWin2, 0)
    _WinAPI_DrawText($hDC2, $rInput2, $tRect2, BitOR($DT_VCENTER, $DT_CENTER, $DT_NOCLIP))

    [/autoit] [autoit][/autoit] [autoit]

    ; DC wieder freigeben, Font löschen & von Strukturen reservierten Speicher freigeben.
    _WinAPI_ReleaseDC(GUICtrlGetHandle($gWin1), $hDC1)
    _WinAPI_ReleaseDC(GUICtrlGetHandle($gWin2), $hDC2)
    _WinAPI_DeleteObject($hFont)
    $tPoint1 = 0
    $tPoint2 = 0
    $tRect1 = 0
    $tRect2 = 0
    EndFunc ;==>Drawing
    Func GetRect($gWin)
    ;reelle Größe des Fonts messen
    Local $aCoords[100][100]
    For $iX = 0 To 99
    For $iY = 0 To 99
    $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
    If Dec($iPixelColor) < Dec('999999') Then
    $rLinks = 100 - $iX
    ExitLoop
    EndIf
    Next
    Next
    For $iY = 0 To 99
    For $iX = 0 To 99
    $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
    If Dec($iPixelColor) < Dec('999999') Then
    $rUnten = 100 - $iY
    ExitLoop
    EndIf
    Next
    Next
    For $iX = 99 To 0 Step -1
    For $iY = 99 To 0 Step -1
    $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
    If Dec($iPixelColor) < Dec('999999') Then
    $rRechts = $iX
    ExitLoop
    EndIf
    Next
    Next
    For $iY = 99 To 0 Step -1
    For $iX = 99 To 0 Step -1
    $iPixelColor = PixelGetColor($iX, $iY, GUICtrlGetHandle($gWin))
    If Dec($iPixelColor) < Dec('999999') Then
    $rOben = $iY
    ExitLoop
    EndIf
    Next
    Next
    $rWidth = 100 - ($rRechts + $rLinks)
    $rHeight = 100 - ($rOben + $rUnten)
    Return
    EndFunc ;==>GetRect
    Func cleanup()
    ;~ _GDIPlus_FontDispose($hFont)
    ;~ _GDIPlus_FontFamilyDispose($hFamily)
    ;~ _GDIPlus_StringFormatDispose($hFormat)
    ;~ _GDIPlus_BrushDispose($hBrush)
    ;~ _GDIPlus_GraphicsDispose($hGraphic)
    ;~ _GDIPlus_Shutdown()
    EndFunc ;==>cleanup
    ;Ende
    cleanup()
    Exit

    [/autoit]
  • Mit den Funktionen GetTextMetrics und GetGlyphOutline bekommst du alle nötigen Parameter (und noch mehr)

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <EditConstants.au3>
    #include <File.au3>
    #include <Fontconstants.au3>
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListviewConstants.au3>
    #include <ProgressConstants.au3>
    #include <RegFunc.au3>
    #include <StaticConstants.au3>
    #include <UpDownConstants.au3>
    #include <WindowsConstants.au3>
    Opt("GUIOnEventMode", 1)
    ;OnAutoItExitRegister('cleanup')

    [/autoit] [autoit][/autoit] [autoit]

    ;Data
    $dString = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ä,ö,ü,'
    $aString = StringSplit($dString, ',')
    Local $data[3][$aString[0] + 1]
    For $i = 1 To $aString[0]
    $data[0][$i] = $i
    $data[1][$i] = StringUpper($aString[$i])
    $data[2][$i] = StringLower($aString[$i])
    Next
    $data[0][0] = (UBound($data, 2) - 1)
    ;_ArrayDisplay($data, -1, -1, 1)
    $cDataCount = 1 ;Letter Stellenzähler
    $capi = 0 ;Gross- und Kleinschreibung
    $FontList = _FileListToArray(@WindowsDir & '\Fonts', '*.ttf', 1);Schriftarten aus Windows Fonts Ordner holen
    If @error = 1 Then
    MsgBox(0, "", "No Folders Found.")
    cleanup()
    Exit
    EndIf
    If @error = 4 Then
    MsgBox(0, "", "No Files Found.")
    cleanup()
    Exit
    EndIf
    $var = _GetRegValues('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts');Schriftartennamen aus Windows Registry holen
    Dim $aItems[($FontList[0] + 1)]
    $x = 1
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo

    [/autoit] [autoit][/autoit] [autoit]

    #region ### START Koda GUI section ### Form=C:\Users\IBM\Desktop\Form1.kxf
    $msg = GUICreate("Schriftarten Tool", 587, 245, 215, 124)
    $MenuItem2 = GUICtrlCreateMenu("Datei")
    $MenuItem4 = GUICtrlCreateMenuItem("Optionen", $MenuItem2)
    $MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem2)
    $MenuItem1 = GUICtrlCreateMenu("Hilfe")
    $listview = GUICtrlCreateListView("Nr.|Datei|Name", 277, 12, 305, 158, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE, $LVS_EX_FULLROWSELECT))
    $gWin1 = GUICtrlCreateGraphic(11, 70, 100, 100, $SS_WHITERECT)
    $gWin2 = GUICtrlCreateGraphic(171, 70, 100, 100, $SS_WHITERECT)
    $bUp = GUICtrlCreateButton("Up", 123, 70, 35, 35, -1, $WS_EX_CLIENTEDGE)
    $bDown = GUICtrlCreateButton("Dwn", 123, 135, 35, 35, -1, $WS_EX_CLIENTEDGE)
    $SchriftG = GUICtrlCreateInput('32', 123, 110, 35, 20)
    $updwnSGR = GUICtrlCreateUpdown($SchriftG)
    $bStart = GUICtrlCreateButton("Start", 25, 190, 80, 25, -1, $WS_EX_STATICEDGE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $bAbbruch = GUICtrlCreateButton("Abbruch", 177, 190, 80, 25, -1, $WS_EX_STATICEDGE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Progress1 = GUICtrlCreateProgress(21, 175, 240, 10, -1, $WS_EX_STATICEDGE)
    $bFontDir = GUICtrlCreateButton(@WindowsDir & '\Fonts', 61, 2, 160, 20)
    $Combo1 = GUICtrlCreateCombo("", 41, 27, 200, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $bAllData = GUICtrlCreateButton("Alle Daten", 330, 180, 190, 25)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###
    _GUICtrlListView_SetColumnWidth($listview, 0, 28)
    _GUICtrlListView_SetColumnWidth($listview, 1, 40)
    _GUICtrlListView_SetColumnWidth($listview, 2, 130)
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUICtrlSetOnEvent($bStart, "button")
    GUICtrlSetOnEvent($bUp, "UP")
    GUICtrlSetOnEvent($bDown, "DOWN")

    [/autoit] [autoit][/autoit] [autoit]

    ;GUI Liste schreiben
    For $a = 1 To UBound($var)
    If StringRight($var[$a - 1][2], 3) = 'ttf' Then
    If StringInStr($var[$a - 1][0], 'Bold', 1) = False And StringInStr($var[$a - 1][0], 'Italic', 1) = False And StringInStr($var[$a - 1][0], 'MT Extra', 1) = False Then
    $aItems[$x] = GUICtrlCreateListViewItem($x & '|' & $var[$a - 1][2] & '|' & $var[$a - 1][0], $listview)
    GUICtrlSetOnEvent($aItems[$x], "HandleClicks")
    $x = $x + 1
    EndIf
    EndIf
    Next
    _GUICtrlListView_SetSelectionMark($listview, 0)
    $sTrim = _GUICtrlListView_GetSelectionMark($listview)
    _GUICtrlListView_ClickItem($listview, 0, "left", False, 1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $rAktList = GUICtrlRead($listview)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ;Funktionen
    ;SpecialEvents
    Func SpecialEvents()
    Select
    Case @GUI_CtrlId = $GUI_EVENT_CLOSE
    cleanup()
    Exit
    EndSelect
    EndFunc ;==>SpecialEvents
    ;HandleClicks
    Func HandleClicks()
    $aktSel = GUICtrlRead(GUICtrlRead($listview))
    $aList = StringSplit($aktSel, '|')
    $sTrim = StringTrimRight($aList[3], 11)
    Drawing()
    EndFunc ;==>HandleClicks
    ;button()
    Func button()
    ;$rInput1 = GUICtrlRead($iLetter)
    MsgBox(0, 'Schriftart', GUICtrlRead(GUICtrlRead($listview)), 2)
    Drawing()
    EndFunc ;==>button
    ;UP()
    Func UP()
    If $cDataCount < $aString[0] Then
    $cDataCount = $cDataCount + 1
    EndIf
    ;GUICtrlSetData($iLetter, $new)
    Drawing()
    EndFunc ;==>UP
    ;DOWN()
    Func DOWN()
    If $cDataCount >= 2 Then
    $cDataCount = $cDataCount - 1
    EndIf
    ;GUICtrlSetData($iLetter, $new)
    Drawing()
    EndFunc ;==>DOWN
    Func SchriftGR()
    $sgr = GUICtrlRead($SchriftG)
    If $sgr <= 8 Then
    GUICtrlSetData($SchriftG, 8)
    EndIf
    If $sgr >= 60 Then
    GUICtrlSetData($SchriftG, 60)
    EndIf
    Drawing()
    EndFunc ;==>SchriftGR
    Func Drawing()
    ;~ GUICtrlSetColor($gWin1, 0)
    ;~ $rInput1 = 'A' ;GUICtrlRead($iLetter)
    ;~ $sgr = GUICtrlRead($SchriftG)
    ;~ _GDIPlus_Startup()
    ;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND($msg)
    ;~ $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    ;~ $hFormat = _GDIPlus_StringFormatCreate()
    ;~ $hFamily = _GDIPlus_FontFamilyCreate($sTrim)
    ;~ $hFont = _GDIPlus_FontCreate($hFamily, $sgr, 0, 2)
    ;~ $tLayout = _GDIPlus_RectFCreate(0, 0, 100, 100)
    ;~ $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $rInput1, $hFont, $tLayout, $hFormat)
    ;~ $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    ;~ $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    ;~ cleanup()
    ;~ _GDIPlus_Startup()
    ;~ $hWind = WinGetHandle($oForm)
    ;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWind)
    ;~ $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic)
    ;~ $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    ;~ _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF)
    ;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND($msg)
    ;~ $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    ;~ $hFormat = _GDIPlus_StringFormatCreate()
    ;~ $hFamily = _GDIPlus_FontFamilyCreate($sTrim)
    ;~ $hFont = _GDIPlus_FontCreate($hFamily, $sgr, 0, 2)
    ;~ $tLayout = _GDIPlus_RectFCreate(50 - ($iWidth / 2), 50 - ($iHeight / 2), 100, 100)
    ;~ $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $rInput1, $hFont, $tLayout, $hFormat)
    ;~ _GDIPlus_GraphicsDrawStringEx($hGraphic, $rInput1, $hFont, $aInfo[0], $hFormat, $hBrush)

    [/autoit] [autoit][/autoit] [autoit]

    Local $iRectWidth, $iRectHeight, $aCtrlPos1
    GUICtrlSetColor($gWin1, 0)
    GUICtrlSetColor($gWin2, 0)
    $rInput = 'A' ;GUICtrlRead($iLetter)
    $rInput1 = StringUpper($rInput)
    $rInput2 = StringLower($rInput)
    $sgr = GUICtrlRead($SchriftG)
    ; Größe des Graphic-Controls ermitteln (Noch 100x100, aber wer weiß, wann sich das ändert)
    $aCtrlPos1 = ControlGetPos($msg, '', $gWin1)
    $aCtrlPos2 = ControlGetPos($msg, '', $gWin2)
    $iRectWidth = $aCtrlPos1[2]
    $iRectHeight = $aCtrlPos1[3]
    ; DC vom Graphics-Control holen
    $hDC1 = _WinAPI_GetDC(GUICtrlGetHandle($gWin1))
    $hDC2 = _WinAPI_GetDC(GUICtrlGetHandle($gWin2))
    ; Font erstellen
    ;$iDeviceCapY = _WinAPI_GetDeviceCaps($hDC1, $__WINAPICONSTANT_LOGPIXELSX)
    ;MsgBox(0, '', $iDeviceCapY)
    $hFont = _WinAPI_CreateFont($sgr, 0, 0, 0, $FW_NORMAL, False, False, False _
    , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $sTrim)
    ; Font mit DC verbinden
    _WinAPI_SelectObject($hDC1, $hFont)
    _WinAPI_SelectObject($hDC2, $hFont)
    ; Textgröße ermitteln

    [/autoit] [autoit][/autoit] [autoit]

    $tPoint1 = _WinAPI_GetTextExtentPoint32($hDC1, $rInput1)
    $tPoint2 = _WinAPI_GetTextExtentPoint32($hDC2, $rInput2)

    [/autoit] [autoit][/autoit] [autoit]

    $aBB1 = _CharGetBlackBox($hDC1, $rInput1)
    $aBB2 = _CharGetBlackBox($hDC2, $rInput2)

    [/autoit] [autoit][/autoit] [autoit]

    $tRect = DllStructCreate($tagRECT)

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - $aBB1[0] - ($aBB1[2] / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - $aBB1[1] - ($aBB1[3] / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint1, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint1, 'y'))
    _WinAPI_DrawText($hDC1, $rInput1, $tRect, BitOR($DT_VCENTER, $DT_CENTER))

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($tRect, 'left', ($iRectWidth / 2) - $aBB2[0] - ($aBB2[2] / 2))
    DllStructSetData($tRect, 'top', ($iRectHeight / 2) - $aBB2[1] - ($aBB2[3] / 2))
    DllStructSetData($tRect, 'right', DllStructGetData($tRect, 'left') + DllStructGetData($tPoint2, 'x'))
    DllStructSetData($tRect, 'bottom', DllStructGetData($tRect, 'top') + DllStructGetData($tPoint2, 'y'))
    _WinAPI_DrawText($hDC2, $rInput2, $tRect, BitOR($DT_VCENTER, $DT_CENTER))

    [/autoit] [autoit][/autoit] [autoit]

    ; DC wieder freigeben, Font löschen & von Strukturen reservierten Speicher freigeben.
    _WinAPI_ReleaseDC(GUICtrlGetHandle($gWin1), $hDC1)
    _WinAPI_ReleaseDC(GUICtrlGetHandle($gWin2), $hDC2)
    _WinAPI_DeleteObject($hFont)
    $tPoint1 = 0
    $tPoint2 = 0
    $tRect = 0
    EndFunc ;==>Drawing

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _CharGetBlackBox($hDC, $sChar)
    Local $tTEXTMETRIC = DllStructCreate($tagTEXTMETRIC)
    DllCall("gdi32.dll", "bool", "GetTextMetricsW", "handle", $hDC, "ptr", DllStructGetPtr($tTEXTMETRIC))

    [/autoit] [autoit][/autoit] [autoit]

    Local $tGLYPHMETRICS = DllStructCreate("UINT gmBlackBoxX; UINT gmBlackBoxY; Long OriginX; Long OriginY; SHORT gmCellIncX; SHORT gmCellIncY;")
    Local $tMatrix = DllStructCreate("SHORT[8];")
    DllStructSetData($tMatrix, 1, 1, 2)
    DllStructSetData($tMatrix, 1, 1, 8)

    [/autoit] [autoit][/autoit] [autoit]

    DllCall('gdi32.dll', "INT", "GetGlyphOutline", "HWND", $hDC, "UINT", Asc($sChar), "UINT", "GGO_METRICS", "PTR", DllStructGetPtr($tGLYPHMETRICS), "UINT", 0, "PTR", 0, "PTR", DllStructGetPtr($tMatrix))

    [/autoit] [autoit][/autoit] [autoit]

    Local $aReturn[4]
    $aReturn[0] = DllStructGetData($tGLYPHMETRICS, "OriginX")
    $aReturn[1] = DllStructGetData($tTEXTMETRIC, "tmAscent") - DllStructGetData($tGLYPHMETRICS, "OriginY")
    $aReturn[2] = DllStructGetData($tGLYPHMETRICS, "gmBlackBoxX")
    $aReturn[3] = DllStructGetData($tGLYPHMETRICS, "gmBlackBoxY")

    [/autoit] [autoit][/autoit] [autoit]

    Return $aReturn
    EndFunc ;==>_CharGetBlackBox

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; Clean up resources
    Func cleanup()
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    EndFunc ;==>cleanup
    ;Ende
    cleanup()
    Exit

    [/autoit]

    E

  • Ja, das sieht schon sehr gut aus, aber bei manchen Schriftarten wird das "$tagRECT" nicht richtig berechnet!! Da wird die Schrift abgeschnitten, bei manchen unten bei manchen rechts..werd mal gucken..kenn die Befehle nicht. Bsp. Schriftart "vladimir.ttf" oder "kunstler.ttf"
    Ich werd mir die GetTextMetrics und GetGlyphOutline bzw. OUTLINETEXTMETRIC nochmal angucken..da stand iwas vonwegen den "Italic" Schriften..das der eine Buchstabe schon unter einem anderen anfängt..usw.!
    Kann man das "$tagRECT" nicht mithilfe der Schwarzwerte im Bild berechnen?? Das wär doch dann genau!?! 8)

    Danke für die Antworten!

    2 Mal editiert, zuletzt von Morrison (5. Februar 2012 um 16:48)