Bunte Labels erzeugen

  • Mit Hilfe des Skriptes TextMeter von Bugfix und auf Grund dieses Posts, habe ich ein Skript geschrieben, welches einfach mehrfärbige Labels erzeugt.

    Viel Spaß damit!

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    GUICreate('Bunte Labels by funkey', 500, 200)

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

    _GuiCtrlCreateColoredLabel('Hallo[0x0000FF] Autoit.de![0x00FF00] Wie gefällt euch das?[0xFF0000]', 20, 20, 'Arial', 20)
    _GuiCtrlCreateColoredLabel('D[0xFF00FF]a[0x0000FF]s[0x00FFFF] ist[0x00FF00] e[0xFFFF00]in[0xFFFFFF] ers[0x000000]ter Farb[0xFF0000]test[0x0000FF]', 20, 80, 'Times New Roman', 15)

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

    GUISetState()

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

    _GuiCtrlCreateColoredLabel('A[0x0000FF]n[0xFF0000]i[0x0000FF]m[0xFF0000]a[0x0000FF]t[0xFF0000]i[0x0000FF]o[0xFF0000]n[0x0000FF] :)[0x00FFFF]', 40, 130, 'Microsoft Sans Serif', 45, 6, 300)

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

    Do
    Sleep(10)
    Until GUIGetMsg() = -3

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

    Func _GuiCtrlCreateColoredLabel($sText, $iPosX, $iPosY, $sFont = 'Microsoft Sans Serif', $iFontSize = 8.5, $iFontAttributes = 0, $iSleep = 0)
    ;Author: funkey
    Local $aTextPart = StringRegExp($sText, '.+?]', 3)
    Local $aText, $hLabel[UBound($aTextPart)], $aSize[2] = [0, 0], $iWidthOld
    For $i = 0 To UBound($aTextPart) - 1
    $aText = StringSplit(StringTrimRight($aTextPart[$i], 1), '[', 2)
    $iWidthOld += $aSize[0] - $iFontSize / 2
    $aSize = _GetTextSize($aText[0], $sFont, $iFontSize, $iFontAttributes)
    $hLabel[$i] = GUICtrlCreateLabel($aText[0], $iPosX + $iWidthOld, $iPosY, $aSize[0], $aSize[1])
    GUICtrlSetColor(-1, $aText[1])
    GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
    GUICtrlSetFont(-1, $iFontSize, 400, $iFontAttributes, $sFont)
    Sleep($iSleep)
    Next
    Return $hLabel
    EndFunc ;==>_GuiCtrlCreateColoredLabel

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

    Func _GetTextSize($nText, $sFont = 'Microsoft Sans Serif', $iFontSize = 8.5, $iFontAttributes = 0)
    ;Author: Bugfix
    ;Modified: funkey
    If $nText = '' Then Return
    Local $hGui = GUICreate("Textmeter by Bugfix")
    _GDIPlus_Startup()
    Local $hFormat = _GDIPlus_StringFormatCreate(0)
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
    Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGui)
    Local $aSize[2] = [$iWidth, $iHeight]
    Return $aSize
    EndFunc ;==>_GetTextSize

    [/autoit]

    Edit: Beispiel-Schriftart geändert

  • Ich bekomme leider nur das graue GUI-Fenster mit Titelleiste, aber keine Labels und schon gar nicht bunt ... :(

    (Nutze hier Win2000 - kann doch kein Problem sein, oder?)

    -Rasta-

  • Bei meinem Win2000 habe ich die GDIPlus.dll über diverse .NET Installationen mitbekommen.
    Sie ist also im System vorhanden.
    Die im Skript benutzten Schriften habe ich auch.
    Aber das einzig erscheinende Grund-GUI-Fenster bleibt grau.

    -Rasta-

  • Hab das Skript jetzt ebenfalls auf Win200 getestet. Es waren wirklich keine Label zu sehen. Danach habe ich die Datei gdiplus.dll von einem WinXP SP2 Rechner entnommen, einfach bei Win2000 ins System32-Verzeichnis kopiert und schon lief es einwandfrei. Ich musste die Dll nicht mal registrieren.
    Rasta, ich habe gelesen, dass es alte Versionen von gdiplus.dll gibt. Vllt hast du eine solche?

  • Super umgesetzt! Habe ich auch gleich mal archiviert. :thumbup:

    Da schließe ich mich mal zu 100 v. H. an !!! :thumbup:

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl