Label-Text senktrecht ?

  • Hallo zusammen,

    gibt es eine Möglichkeit einen Label-Text (z.B. über GUICtrlCreateLabel) senkrecht (oder besser noch beliebigen Winkel) ausrichten zu können?
    Ich meine nicht, das die Buchstaben senkrecht untereinander stehen, das ist einfach.

    Es muss auch nicht über GUICtrlCreateLabellaufen, kann auch beliebige andere Funktion sein, mir ist nur wichtig das ich ein Wort drehen kann.
    Es würde schon reichen wenn es um 90° nach links gedreht wäre...

    Gruß und Dank
    Ralf

    Einmal editiert, zuletzt von Eisenbahn_Ralf (8. August 2012 um 13:37) aus folgendem Grund: Lösung gefunden

    • Offizieller Beitrag

    Habe dies hier in meinen Snippets gefunden. Kommt aus'm Forum.

    Spoiler anzeigen
    [autoit]

    #include <Misc.au3>
    #include <StructureConstants.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <WinAPI.au3>
    #include <GuiConstantsEx.au3>

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

    Global Const $iOpacity = 200
    ;~ Global Const $ULW_ALPHA = 2
    Global Const $nPI = 3.1415926535897932384626433832795
    ;~ Global Const $WM_LBUTTONDOWN = 0x0201 ; Drag Window 1 of 3 addin
    Global $hGui, $hGraphic
    Global $dll = DllOpen("user32.dll")
    Global $GuiSize = 580, $w2 = 144, $h2 = 20
    Global $randcol, $fCol, $fontSize = 12, $fRot = -144, $w = 100, $h = 20, $nAngle = 0, $flg = 1
    Opt("MustDeclareVars", 1)
    Opt("GUIOnEventMode", 1)

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

    TextRotate()

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

    Func TextRotate()
    Local $hWnd, $hDC, $hBitmap, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hGui = GUICreate("Rotate Text", $GuiSize, $GuiSize, -1, -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUIRegisterMsg($WM_LBUTTONDOWN, "_WinMove") ; Drag Window 2 of 3 addin
    GUISetState()

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

    Do
    _GDIPlus_Startup()
    $hWnd = _WinAPI_GetDC(0)
    $hDC = _WinAPI_CreateCompatibleDC($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $GuiSize, $GuiSize) ; $iWidth, $iHeight)
    _WinAPI_SelectObject($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)

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

    If _IsPressed("11") Then $flg += 1 ; CTRL key
    If $flg = 1 Then RotateText2()
    If $flg = 2 Then RotateText()
    If $flg >= 3 Then $flg = 1

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

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $GuiSize) ;$iWidth )
    DllStructSetData($tSize, "Y", $GuiSize) ;$iHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    Sleep(200)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_ReleaseDC(0, $hWnd)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hDC)
    _GDIPlus_Shutdown()
    Until _IsPressed("1B") ; ESC key
    DllClose($dll)
    EndFunc ;==>TextRotate

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

    Func RotateText()
    Local $txt, $txtlen, $fontSize = 12
    $txt = "Autoit Sang" ; Type text to be displayed here - text box display autosizing below
    $txtlen = StringLen($txt)

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

    $fRot = $fRot + 1
    If $fRot = 144 Then $fRot = -144 ; 72*5deg=360deg - 2/360's before zero & 2/360's after zero
    If $fRot < 0 Then
    $nAngle = Mod($nAngle - 5, 360) ; 5deg increments (minus anticlockwise)
    Else
    $nAngle = Mod($nAngle + 5, 360) ; 5deg increments (plus clockwise)
    EndIf

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

    ;Text box display autosizing. $w - Width of text rectangle; $h - Heigth of text rectangle
    $w = Int($fontSize * $txtlen * 3 / 4)
    $h = Int(($fontSize * 4 / 3) * (1280 / 1024))

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

    If $fCol = 0 Then ;Randomize ARGB color
    $randcol = "0xff" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2)
    EndIf
    $fCol = Mod($fCol + 1, 18) ; Changes color every 18 * 5deg = 90Deg

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

    ;DrawText( $nX, $nY, $nAngle, $iWidth, $iHeight, $txt, $iARGB , $fontSize )
    DrawText($GuiSize / 4, $GuiSize / 4, $nAngle, $w, $h, $txt, $randcol)

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

    Return 1
    EndFunc ;==>RotateText

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

    Func RotateText2()
    Local $txt2, $txtlen2, $winpos

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

    $txt2 = "Autoit Sang" ; Type text to be displayed here - text box display autosizing below
    $txtlen2 = StringLen($txt2)

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

    $fRot = $fRot + 1
    If $fRot = 144 Then $fRot = -144 ; 72*5deg=360deg - 2/360's before zero & 2/360's after zero
    If $fRot < 0 Then
    $nAngle = Mod($nAngle - 5, 360) ; 5deg increments (minus anticlockwise)
    $fontSize = 12 + Int(($fRot + 144) * 20 / 144); increase fontsize 12 to size 32 over 144 increments
    Else
    $nAngle = Mod($nAngle + 5, 360) ; 5deg increments (plus clockwise)
    $fontSize = 32 - Int(($fRot) * 20 / 144); decrease fontsize 32 to size 12 over 144 increments
    EndIf

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

    ;$w2 - Width of text rectangle; $h2 - Heigth of text rectangle
    $w2 = Int($fontSize * $txtlen2 * 3 / 4)
    $h2 = Int(($fontSize * 4 / 3) * (1280 / 1024))

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

    $winpos = WinGetPos($hGui)
    WinMove("Rotate Text", "", Mod($winpos[0] + 1, @DesktopWidth / 2), $winpos[1])

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

    If $fCol = 0 Then ;Randomize ARGB color
    $randcol = "0xff" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2)
    EndIf
    $fCol = Mod($fCol + 1, 18) ; Changes color 18 * 5deg = 90Deg

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

    ;DrawText( $nX, $nY, $nAngle, $iWidth, $iHeight, $txt, $iARGB , $fontSize )
    DrawText($GuiSize / 2, $GuiSize / 2, $nAngle, $w2, $h2, $txt2, $randcol, $fontSize)
    Sleep(40)
    Return 1
    EndFunc ;==>RotateText2

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

    Func DrawText($nX, $nY, $nAngle, $nWidth, $nHeight, $txt, $iARGB = 0xFF000000, $fontSize = 12)
    Local $hMatrix, $nXt, $nYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $x, $y
    ; $nXt - The X coordinate of the upper left corner of the Graphics object before rotation
    ; $nYt - The Y coordinate of the upper left corner of the Graphics object before rotation

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

    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixRotate($hMatrix, $nAngle, 1)
    _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)

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

    ;x, y display coordinates of center of height of the rectanglular text box ($height/2).
    ;x, y increment in a circular path with radius (width of text box)/2.
    $x = ($nWidth / 2) * Cos($nAngle * $nPI / 180) - ($nHeight / 2) * Sin($nAngle * $nPI / 180);Parametric equations for a circle
    $y = ($nWidth / 2) * Sin($nAngle * $nPI / 180) + ($nHeight / 2) * Cos($nAngle * $nPI / 180); and adjusts for center of text box

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

    ;Rotation of Coordinate Axes formulae
    ;Use $nXt, $nYt in _GDIPlus_RectFCreate. These x, y values is the handle of the rectangular text box point
    ; before rotation (translation of the matrix)
    $nXt = ($nX - $x) * Cos($nAngle * $nPI / 180) + ($nY - $y) * Sin($nAngle * $nPI / 180) ; $nXt - X coordinate before translation
    $nYt = -($nX - $x) * Sin($nAngle * $nPI / 180) + ($nY - $y) * Cos($nAngle * $nPI / 180) ; $nYt - Y coordinate before translation

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

    ; Parameters for lus_GraphicsDrawStringEx()
    $hBrush = _GDIPlus_BrushCreateSolid($iARGB)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    ;$hFont = _GDIPlus_FontCreate ($hFamily, 32, 1)
    $hFont = _GDIPlus_FontCreate($hFamily, $fontSize, 1)
    $tLayout = _GDIPlus_RectFCreate($nXt, $nYt, $nWidth, $nHeight)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $txt, $hFont, $tLayout, $hFormat, $hBrush)
    Sleep(20)
    ; Clean up resources
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    Return 1
    EndFunc ;==>DrawText

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

    ; =================================================================
    ; Drag Window 3 of 3 addin
    ; =================================================================
    Func _WinMove($hWnd, $Command, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)
    EndFunc ;==>_WinMove

    [/autoit]