- Offizieller Beitrag
Hi,
nachdem ich Dank kräftiger Unterstützung von progandy ( ) 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
; ver 3.2.12.1
#Include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
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)
GUISetState()
Global $Rect
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
;==================================================================================================
; 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, 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
Edit: Hier mal eine Ansicht
http://www.bilder-space.de/show.php?file=…19cXqB3AiTr.JPG