Text auf GUI in jedem gewünschten Winkel

    • Offizieller Beitrag

    Hi,
    nachdem ich Dank kräftiger Unterstützung von progandy ( :thumbup: ) das Bsp. aus dem Api-Guide zum "RotateText" umsetzen konnte, habe ich daraus mal eine Funktion erstellt, damit es auch allgemeingültig verwendet werden kann. Ich denke, das könnte von größerem Interesse sein.
    Im angehängten Bsp. findet ihr eine Oberfläche, in der ihr die verschiedenen Parameter der Funktion ausprobieren könnt. Eine Möglichkeit, den geschriebenen Text zu löschen, habe ich noch nicht gefunden (außer mit Leerzeichen überschreiben ;) ). Vielleicht habt ihr ja eine Idee.
    Danke funkey für den Tipp zum Löschen.

    Edit: Habe auf Anregung von funkey noch den Parameter zum Neuzeichnen (und somit Löschen alter Beschriftung) der GUI mit Standardwert TRUE eingefügt.

    Edit: Nun noch Parameter für Schriftfarbe/Hintergrundfarbe eingefügt. Jetzt sollte es aber wirklich kpl. sein. ;)

    Spoiler anzeigen
    [autoit]

    ; ver 3.2.12.1
    #Include <WinAPI.au3>
    #include <GUIConstantsEx.au3>
    #include <StructureConstants.au3>
    #include <WindowsConstants.au3>

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

    Global $GUI = GUICreate('Test Rotation')
    GUICtrlCreateLabel('Text:', 10, 13, 50, 17)
    Global $In = GUICtrlCreateInput('Hallo!', 70, 10, 150, 20)
    Global $bt = GUICtrlCreateButton('Schreibe Text', 250, 10, 100, 20)
    Global $btDel = GUICtrlCreateButton('Lösche Text', 250, 40, 100, 20)
    GUICtrlCreateLabel('Pos. X:', 10, 43, 50, 17)
    Global $inX = GUICtrlCreateInput('80', 70, 40, 30, 20)
    GUICtrlCreateLabel('Pos. Y:', 110, 43, 50, 17)
    Global $inY = GUICtrlCreateInput('280', 170, 40, 30, 20)
    GUICtrlCreateLabel('Winkel:', 10, 73, 50, 17)
    Global $inDeg = GUICtrlCreateInput('30', 70, 70, 30, 20)
    GUICtrlCreateLabel('Höhe:', 110, 73, 50, 17)
    Global $inSize = GUICtrlCreateInput('60', 170, 70, 30, 20)
    GUICtrlCreateLabel('Breite:', 10, 103, 50, 17)
    Global $inWeight = GUICtrlCreateInput('400', 70, 100, 30, 20)
    GUICtrlCreateLabel('Font:', 110, 103, 50, 17)
    Global $inFont = GUICtrlCreateInput('Comic Sans MS', 170, 100, 200, 20)
    GUICtrlCreateGroup(' Stil ', 10, 130, 280, 40)
    Global $rDef = GUICtrlCreateRadio('Standard', 15, 145, 65)
    GUICtrlSetState(-1, $GUI_CHECKED)
    Global $rIt = GUICtrlCreateRadio('Italic', 85, 145, 45)
    Global $cbUn = GUICtrlCreateCheckbox('Underlined', 135, 145, 70)
    Global $cbSt = GUICtrlCreateCheckbox('StrikeOut', 215, 145, 70)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateLabel('Farbe Schrift:', 10, 183, 80, 17)
    Global $inCol = GUICtrlCreateInput('', 90, 180, 60, 20)
    GUICtrlCreateLabel('Hintergrund:', 160, 183, 80, 17)
    Global $inbCol = GUICtrlCreateInput('', 230, 180, 60, 20)

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

    GUISetState()
    Global $Rect

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

    Do
    $msg = GUIGetMsg()
    If $msg = $bt Then
    Local $type = 1
    If BitAND(GUICtrlRead($rIt), $GUI_CHECKED) Then $type = 2
    If BitAND(GUICtrlRead($cbUn), $GUI_CHECKED) Then $type += 4
    If BitAND(GUICtrlRead($cbSt), $GUI_CHECKED) Then $type += 8
    Local $readFont = GUICtrlRead($inFont)
    If $readFont = '' Then $readFont = -1
    Local $col = GUICtrlRead($inCol), $bkcol = GUICtrlRead($inbCol)
    If $col = '' Then $col = -1
    If $bkcol = '' Then $bkcol = -1
    _WriteRotateText($GUI, GUICtrlRead($In), GUICtrlRead($inX), GUICtrlRead($inY), GUICtrlRead($inDeg), _
    GUICtrlRead($inSize), GUICtrlRead($inWeight), $type, $readFont, $col, $bkcol)
    ElseIf $msg = $btDel Then
    _WinAPI_RedrawWindow($GUI)
    EndIf
    Until $msg = $GUI_EVENT_CLOSE

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

    ;==================================================================================================
    ; Function Name: _WriteRotateText($hWnd, $sWrite, $iX, $iY, $iDeg, $iSize [, $iWeight=400 _
    ; [, $iType=1 [, $sFont=-1 [, $iCol=-1 [, $iBkCol=-1 [,$bRedraw=True]]]]]])
    ; Description: Schreibt einen Text mit bestimmtem Winkel in das angegebene Fenster
    ; Parameter(s): $hWnd Handle des Fensters
    ; $sWrite der zu schreibende Text
    ; $iX x-Position auf dem Fenster
    ; $iY y-Position auf dem Fenster
    ; $iDeg Rotationswinkel des Textes
    ; $iSize Höhe des Textes
    ; optional: $iWeight Fontbreite 0 - 1000 (Standard 400)
    ; optional: $iType Fonttyp 1=normal (Standard); 2=Italic; 4=Underline; 8=StrikeOut
    ; 1 oder 2 können mit 4 und 8 kombiniert werden (5;9 od. 6;10)
    ; optional: $sFont Fontname -1=Font der Form (Standard)
    ; optional: $iCol Fontfarbe -1=schwarz (Standard)
    ; optional: $iBkCol Hintergrundfarbe -1=Hintergrundfarbe des Fensters (Standard)
    ; optional: $bRedraw True=Fenster vorher neu zeichnen (vorige Beschriftung löschen - Standard)
    ; Requirement(s): #Include <WinAPI.au3>; #include <StructureConstants.au3>; #include <WindowsConstants.au3>
    ;==================================================================================================
    Func _WriteRotateText($hWnd, $sWrite, $iX, $iY, $iDeg, $iSize, $iWeight=400, $iType=1, $sFont=-1, $iCol=-1, $iBkCol=-1, $bRedraw=True)
    If $bRedraw Then _WinAPI_RedrawWindow($hWnd)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 'Left', $iX)
    DllStructSetData($tRect, 'Top', $iY)
    Local $rotate = $iDeg *10
    If ($rotate = 900) Or ($rotate = 1800) Or ($rotate = 2700) Then $rotate += 1
    Local $RotateMe = DllStructCreate($tagLOGFONT)
    DllStructSetData($RotateMe, 'Escapement', $rotate)
    DllStructSetData($RotateMe, 'Height', ($iSize * -20)/_WinAPI_TwipsPerPixelY())
    If $iWeight <> 400 Then DllStructSetData($RotateMe, 'Weight', $iWeight)
    If BitAND($iType, 2) Then DllStructSetData($RotateMe, 'Italic', True)
    If BitAND($iType, 4) Then DllStructSetData($RotateMe, 'Underline', True)
    If BitAND($iType, 8) Then DllStructSetData($RotateMe, 'StrikeOut', True)
    If $sFont <> -1 Then DllStructSetData($RotateMe, 'FaceName', $sFont)
    Local $rFont = _WinAPI_CreateFontIndirect($RotateMe)
    Local $hDC = _WinAPI_GetDC($hWnd)
    If $iCol <> -1 Then _WinAPI_SetTextColor($hDC, $iCol)
    If $iBkCol <> -1 Then _WinAPI_SetBkColor($hDC, $iBkCol)
    _WinAPI_SelectObject($hdc, $rFont)
    _WinAPI_DrawText($hDC, $sWrite, $tRect, BitOR($DT_NOCLIP,$DT_NOPREFIX))
    _WinAPI_ReleaseDC($hWnd, $hDC)
    EndFunc ;==>_WriteRotateText

    [/autoit]

    Edit: Hier mal eine Ansicht
    http://www.bilder-space.de/show.php?file=…19cXqB3AiTr.JPG

  • Gefällt mir sehr gut!!
    Mit Checkboxen kannst du verschiedene Stile kombinieren.

    Spoiler anzeigen
    [autoit]

    ; Version 3.2.12.1
    #Include <WinAPI.au3>
    #include <GUIConstantsEx.au3>
    #include <StructureConstants.au3>
    #include <WindowsConstants.au3>

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

    Global $GUI = GUICreate('Test Rotation')
    GUICtrlCreateLabel('Text:', 10, 13, 50, 17)
    Global $In = GUICtrlCreateInput('Hallo!', 70, 10, 150, 20)
    Global $bt = GUICtrlCreateButton('Schreibe Text', 250, 10, 100, 20)
    GUICtrlCreateLabel('Pos. X:', 10, 43, 50, 17)
    Global $inX = GUICtrlCreateInput('80', 70, 40, 30, 20)
    GUICtrlCreateLabel('Pos. Y:', 110, 43, 50, 17)
    Global $inY = GUICtrlCreateInput('280', 170, 40, 30, 20)
    GUICtrlCreateLabel('Winkel:', 10, 73, 50, 17)
    Global $inDeg = GUICtrlCreateInput('30', 70, 70, 30, 20)
    GUICtrlCreateLabel('Höhe:', 110, 73, 50, 17)
    Global $inSize = GUICtrlCreateInput('60', 170, 70, 30, 20)
    GUICtrlCreateLabel('Breite:', 10, 103, 50, 17)
    Global $inWeight = GUICtrlCreateInput('400', 70, 100, 30, 20)
    GUICtrlCreateLabel('Font:', 110, 103, 50, 17)
    Global $inFont = GUICtrlCreateInput('Comic Sans MS', 170, 100, 200, 20)
    GUICtrlCreateGroup(' Stil ', 10, 130, 280, 40)
    ;~ Global $rDef = GUICtrlCreateCheckbox('Standard', 15, 145, 65)
    ;~ GUICtrlSetState(-1, $GUI_CHECKED)
    Global $rIt = GUICtrlCreateCheckbox('Italic', 85, 145, 45)
    Global $rUn = GUICtrlCreateCheckbox('Underlined', 135, 145, 70)
    Global $rSt = GUICtrlCreateCheckbox('StrikeOut', 215, 145, 70)
    GUICtrlCreateGroup("", -99, -99, 1, 1)

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

    GUISetState()
    Global $Rect

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

    Do
    $msg = GUIGetMsg()
    If $msg = $bt Then
    Local $type = BitAND(GUICtrlRead($rIt), $GUI_CHECKED)&BitAND(GUICtrlRead($rUn), $GUI_CHECKED)&BitAND(GUICtrlRead($rSt), $GUI_CHECKED)
    Local $readFont = GUICtrlRead($inFont)
    If $readFont = '' Then $readFont = -1
    _WriteRotateText($GUI, GUICtrlRead($In), GUICtrlRead($inX), GUICtrlRead($inY), GUICtrlRead($inDeg), _
    GUICtrlRead($inSize), GUICtrlRead($inWeight), $type, $readFont)
    EndIf
    Until $msg = $GUI_EVENT_CLOSE

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

    ;==================================================================================================
    ; Function Name: _WriteRotateText($hWnd, $sWrite, $iX, $iY, $iDeg, $iSize [, $iWeight=400 [, $sType=-1 [, $sFont=-1]]])
    ; Description: Schreibt einen Text mit bestimmtem Winkel in das angegebene Fenster
    ; Parameter(s): $hWnd Handle des Fensters
    ; $sWrite der zu schreibende Text
    ; $iX x-Position auf dem Fenster
    ; $iY y-Position auf dem Fenster
    ; $iDeg Rotationswinkel des Textes
    ; $iSize Höhe des Textes
    ; optional: $iWeight Fontbreite 0 - 1000 (Standard 400)
    ; optional: $sType Fonttyp -1=normal (Standard); 'i'=Italic; 'u'=Underline; 's'=StrikeOut
    ; optional: $sFont Fontname -1=Font der Form (Standard)
    ; Requirement(s): #Include <WinAPI.au3>; #include <StructureConstants.au3>; #include <WindowsConstants.au3>
    ;==================================================================================================
    Func _WriteRotateText($hWnd, $sWrite, $iX, $iY, $iDeg, $iSize, $iWeight=400, $sType=-1, $sFont=-1)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 'Left', $iX)
    DllStructSetData($tRect, 'Top', $iY)
    Local $rotate = $iDeg *10
    If ($rotate = 900) Or ($rotate = 1800) Or ($rotate = 2700) Then $rotate += 1
    Local $RotateMe = DllStructCreate($tagLOGFONT)
    DllStructSetData($RotateMe, 'Escapement', $rotate)
    DllStructSetData($RotateMe, 'Height', ($iSize * -20)/_WinAPI_TwipsPerPixelY())
    If $iWeight <> 400 Then DllStructSetData($RotateMe, 'Weight', $iWeight)

    #Region funkey
    If BitAND($sType, 4) Then DllStructSetData($RotateMe, 'Italic', True)
    If BitAND($sType, 2) Then DllStructSetData($RotateMe, 'Underline', True)
    If BitAND($sType, 1) Then DllStructSetData($RotateMe, 'StrikeOut', True)
    #EndRegion funkey

    If $sFont <> -1 Then DllStructSetData($RotateMe, 'FaceName', $sFont)
    Local $rFont = _WinAPI_CreateFontIndirect($RotateMe)
    Local $hDC = _WinAPI_GetDC($hWnd)
    _WinAPI_SelectObject($hdc, $rFont)
    _WinAPI_DrawText($hDC, $sWrite, $tRect, $DT_NOCLIP)
    _WinAPI_ReleaseDC($GUI, $hDC)
    EndFunc ;==>_WriteRotateText

    [/autoit]


    Edit: Text löschen eventuell mit _WinAPI_RedrawWindow ??

    Spoiler anzeigen
    [autoit]

    Do
    $msg = GUIGetMsg()
    If $msg = $bt Then
    Local $type = BitAND(GUICtrlRead($rIt), $GUI_CHECKED)&BitAND(GUICtrlRead($rUn), $GUI_CHECKED)&BitAND(GUICtrlRead($rSt), $GUI_CHECKED)
    Local $readFont = GUICtrlRead($inFont)
    If $readFont = '' Then $readFont = -1
    _WriteRotateText($GUI, GUICtrlRead($In), GUICtrlRead($inX), GUICtrlRead($inY), GUICtrlRead($inDeg), _
    GUICtrlRead($inSize), GUICtrlRead($inWeight), $type, $readFont)
    Sleep(2000)
    _WinAPI_RedrawWindow($GUI)
    EndIf
    Until $msg = $GUI_EVENT_CLOSE

    [/autoit]

    Edit2: Wenn man ein '&' eingibt wird es nicht dargestellt. Erst '&&' stellt ein '&' dar. 3x& ergibt '&', 4x& ergibt dann '&&'

    • Offizieller Beitrag

    Wenn man ein '&' eingibt wird es nicht dargestellt. Erst '&&' stellt ein '&' dar. 3x& ergibt '&', 4x& ergibt dann '&&'


    Habe ich jetzt korrigiert - wird als normales Schriftzeichen dargestellt.

    Danke für den Tipp mit dem Löschen. Habe das Bsp. umgestellt - aber Kombination 'normale' Schrift od. Italic + unter/durchgestrichen.
    (s. 1. Post)

  • Letzte Meldung von mir heute: :D

    Du könntest noch eine Redraw-Parameter hinzufügen, damit wenn man den Text aktualisiert und der neue Text einen anderen Winkel hat oder kürzer ist als der andere, der alte auch vorher gelöscht wird. Tipp: Gib 'Hallo Freund' ein und danach nur 'Hallo'. Man merkt keinen Unterschied ;)

  • Das ist ja genial!

    Damit lässt sich ja rein theoretisch sowas wie Flaschendrehen machen. den Winkel über Random ermitteln... :D

    Oder eine "Animation"
    Drehen, sleep, ein Grad drehen, sleep, ein grad drehen, sleep :D

    Auf jedem Fall super!

  • Hallo Zusammen,

    habe die _WriteRotateText Funktion in Benutzung!
    Funktioniert soweit ganz gut, nun habe ich aber eine Frage!

    Wie kann ich 2 verschiedene texte schreiben, wobei sich einer der texte laufzeitabhänging ändern soll!

    hab es mal so gemacht, ist aber nicht gerade gut gelöst, weil man immer beide texte angeben muss!

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #Include <WinAPI.au3>
    #include <GUIConstantsEx.au3>
    #include <StructureConstants.au3>
    #include <WindowsConstants.au3>

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

    $Parent = GUICreate("", 400, 400,-1,-1, $WS_POPUP + $WS_EX_LAYERED );270,137
    WinSetTrans($Parent, "", 0)
    GUISetState(@SW_SHOW)
    $rot_txt01 = _WriteRotateText($Parent, "Version 1.1.6.5", 150, 80, -9, 12, 0, 1, -1, -1, -1, False)
    $rot_txt02 = _WriteRotateText($Parent, "... Programm wird vorbereitet ...", 110, 105, -9, 10, 0, 1, -1, -1, -1, False)
    _WinAPI_SetLayeredWindowAttributes($Parent, 0xFFFFFF) ;setzt transparente farbe, hier weiß

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

    Sleep(2000)

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

    _WinAPI_RedrawWindow($Parent)
    $rot_txt01 = _WriteRotateText($Parent, "Version 1.1.6.5", 150, 80, -9, 12, 0, 1, -1, -1, -1, False)
    $rot_txt02 = _WriteRotateText($Parent, "... bitte warten ...", 110, 105, -9, 10, 0, 1, -1, -1, -1, False)

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

    Sleep(2000)

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

    _WinAPI_RedrawWindow($Parent)
    $rot_txt01 = _WriteRotateText($Parent, "Version 1.1.6.5", 150, 80, -9, 12, 0, 1, -1, -1, -1, False)
    $rot_txt02 = _WriteRotateText($Parent, "...test 12343 ...", 110, 105, -9, 10, 0, 1, -1, -1, -1, False)

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

    ;test ende
    Sleep(20000000)

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

    ;==================================================================================================
    ; Function Name: _WriteRotateText($hWnd, $sWrite, $iX, $iY, $iDeg, $iSize [, $iWeight=400 _
    ; [, $iType=1 [, $sFont=-1 [, $iCol=-1 [, $iBkCol=-1 [,$bRedraw=True]]]]]])
    ; Description: Schreibt einen Text mit bestimmtem Winkel in das angegebene Fenster
    ; Parameter(s): $hWnd Handle des Fensters
    ; $sWrite der zu schreibende Text
    ; $iX x-Position auf dem Fenster
    ; $iY y-Position auf dem Fenster
    ; $iDeg Rotationswinkel des Textes
    ; $iSize Höhe des Textes
    ; optional: $iWeight Fontbreite 0 - 1000 (Standard 400)
    ; optional: $iType Fonttyp 1=normal (Standard); 2=Italic; 4=Underline; 8=StrikeOut
    ; 1 oder 2 können mit 4 und 8 kombiniert werden (5;9 od. 6;10)
    ; optional: $sFont Fontname -1=Font der Form (Standard)
    ; optional: $iCol Fontfarbe -1=schwarz (Standard)
    ; optional: $iBkCol Hintergrundfarbe -1=Hintergrundfarbe des Fensters (Standard)
    ; optional: $bRedraw True=Fenster vorher neu zeichnen (vorige Beschriftung löschen - Standard)
    ; Requirement(s): #Include <WinAPI.au3>; #include <StructureConstants.au3>; #include <WindowsConstants.au3>
    ;==================================================================================================
    Func _WriteRotateText($hWnd, $sWrite, $iX, $iY, $iDeg, $iSize, $iWeight=400, $iType=1, $sFont=-1, $iCol=-1, $iBkCol=-1, $bRedraw=True)
    If $bRedraw Then _WinAPI_RedrawWindow($hWnd)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 'Left', $iX)
    DllStructSetData($tRect, 'Top', $iY)
    Local $rotate = $iDeg *10
    If ($rotate = 900) Or ($rotate = 1800) Or ($rotate = 2700) Then $rotate += 1
    Local $RotateMe = DllStructCreate($tagLOGFONT)
    DllStructSetData($RotateMe, 'Escapement', $rotate)
    DllStructSetData($RotateMe, 'Height', ($iSize * -20)/_WinAPI_TwipsPerPixelY())
    If $iWeight <> 400 Then DllStructSetData($RotateMe, 'Weight', $iWeight)
    If BitAND($iType, 2) Then DllStructSetData($RotateMe, 'Italic', True)
    If BitAND($iType, 4) Then DllStructSetData($RotateMe, 'Underline', True)
    If BitAND($iType, 8) Then DllStructSetData($RotateMe, 'StrikeOut', True)
    If $sFont <> -1 Then DllStructSetData($RotateMe, 'FaceName', $sFont)
    Local $rFont = _WinAPI_CreateFontIndirect($RotateMe)
    Local $hDC = _WinAPI_GetDC($hWnd)
    If $iCol <> -1 Then _WinAPI_SetTextColor($hDC, $iCol)
    If $iBkCol <> -1 Then _WinAPI_SetBkColor($hDC, $iBkCol) ; wenn Transparenz gewünscht, Folgezeile aktivieren
    ;~ _WinAPI_SetBkMode($hDC, $TRANSPARENT)
    _WinAPI_SelectObject($hdc, $rFont)
    _WinAPI_DrawText($hDC, $sWrite, $tRect, BitOR($DT_NOCLIP,$DT_NOPREFIX))
    _WinAPI_ReleaseDC($hWnd, $hDC)
    EndFunc ;==>_WriteRotateText

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

    hab mir gerade überlegt, den text1 in eine funktion zu packen und diese dann aufrufen, das hätte den vorteil, dass man den text bei einer änderung nur einmal anpassen muss!
    hat einer noch ne idee?

    Gruß gmmg ;)

    Einmal editiert, zuletzt von gmmg (16. Dezember 2010 um 15:59)

  • ich verstehe nicht warum das nicht funktioniert:

    [autoit]

    #include <_WriteRotateText.au3>
    $gui = GUICreate("TEST")
    _WriteRotateText($GUI, "Hallo Welt", 50,50,30,60)
    GUISetState()
    While 1
    WEnd

    [/autoit]

    ich hab in der udf folgende zeilen eingefügt:

    [autoit]

    #include-once
    #Include <WinAPI.au3>
    #include <StructureConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit]