Jump to content

Recommended Posts

Posted

how to create a label with the text fading from left to right, so at the end of the label, the text is barely visible, like so:

image.png.b1b51f8c178e65652bbb53571cae8234.png

this image is a mockup i made in PowerPoint, by putting a gradient transparency rectangle over a normal text box. perhaps this technique is applicable in AutoIt? graphics is not my forte.

thanks for any advice!

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted (edited)

Here one way :

; From Nine
#include <GDIPlus.au3>
#include <GUIConstants.au3>

Opt("MustDeclareVars", True)

Example()

Func Example()
  _GDIPlus_Startup()

  Local $hGUI = GUICreate("Example", 400, 400)
  GUISetState()

  Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
  _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)

  Local $hBrush = _GDIPlus_LineBrushCreate(50, 200, 320, 200, 0xFF000000, 0xFFFFFFFF)

  Local $hFormat = _GDIPlus_StringFormatCreate()
  Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
  Local $hFont = _GDIPlus_FontCreate($hFamily, 28, 2)
  Local $tLayout = _GDIPlus_RectFCreate(80, 100, 320, 40)
  Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, "AutoIt Rulez !", $hFont, $tLayout, $hFormat)
  _GDIPlus_GraphicsDrawStringEx($hGraphic, "AutoIt Rulez !", $hFont, $aInfo[0], $hFormat, $hBrush)

  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE

  _GDIPlus_StringFormatDispose($hFormat)
  _GDIPlus_FontFamilyDispose($hFamily)
  _GDIPlus_FontDispose($hFont)
  _GDIPlus_BrushDispose($hBrush)
  _GDIPlus_GraphicsDispose($hGraphic)
  _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Edited by Nine
Posted (edited)

thank you, that looks nice! i'm now trying to understand the process. is that a "graphic" control that occupies the entire GUI? i'm asking because if i try to set a background color to the GUI, it does not show:

GUISetBkColor($COLOR_YELLOW) ; ^^ not visible. the graphic object takes up the entire GUI?

 

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted
1 hour ago, orbs said:

is that a "graphic" control that occupies the entire GUI?

Yes it is just an example.  I made it like that to simplify the code.  To color the background, replace the line with yellow color :

_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFF00)

 

Posted

ok, so how do i make it more label-like? meaning, for start,  can i specify coordinates and size, rather than let it occupy the entire GUI?

also, does it have a control id? can i make it clickable, resizeable, transparent background, etc?

 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted (edited)
1 hour ago, Nine said:

ps. you can use the hwnd of a label instead of the hwnd of the GUI.

so i created a label, got its handle, and tried to use it, but nothing is displayed:

; From Nine
#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <ColorConstants.au3>

Opt("MustDeclareVars", True)

Example()

Func Example()
    _GDIPlus_Startup()

    Local $hGUI = GUICreate("Example", 420, 420)
    GUISetState()

    ; create a label and use it instead of the entire GUI
    Local $gLabel = GUICtrlCreateLabel('', 10, 10, 400, 400)
    Local $hLabel = GUICtrlGetHandle($gLabel)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hLabel)

    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)

    Local $hBrush = _GDIPlus_LineBrushCreate(50, 200, 320, 200, 0xFF000000, 0xFFFFFFFF)

    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    Local $hFont = _GDIPlus_FontCreate($hFamily, 28, 2)
    Local $tLayout = _GDIPlus_RectFCreate(80, 100, 320, 40)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, "AutoIt Rulez !", $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, "AutoIt Rulez !", $hFont, $aInfo[0], $hFormat, $hBrush)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

am i missing something obvious here?

_GDIPlus_GraphicsCreateFromHWND($hLabel) returns a valid handle, no @error.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted (edited)

Try this version :

; From Nine
#include <WinAPIDiag.au3>
#include <GDIPlus.au3>
#include <GUIConstants.au3>

; Blend - Fade - Text

Opt("MustDeclareVars", True)

Example()

Func Example()
  _GDIPlus_Startup()

  Local $hGUI = GUICreate("Example", 400, 400)
  GUISetBkColor(0xFFFF00)
  Local $idLabel = GUICtrlCreateLabel("", 75, 20, 250, 40)
  Local $hLabel = GUICtrlGetHandle($idLabel)
  GUISetState()

  Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hLabel)

  Local $hBrush = _GDIPlus_LineBrushCreate(0, 20, 250, 20, 0xFF606060, 0xFFFFFFFF)

  Local $hFormat = _GDIPlus_StringFormatCreate()
  Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
  Local $hFont = _GDIPlus_FontCreate($hFamily, 28, 2)
  Local $tLayout = _GDIPlus_RectFCreate(0, 0, 250, 40)
  Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, "AutoIt Rulez !", $hFont, $tLayout, $hFormat)
  ;_WinAPI_DisplayStruct($aInfo[0], $tagGDIPRECTF)
  _GDIPlus_GraphicsDrawStringEx($hGraphic, "AutoIt Rulez !", $hFont, $aInfo[0], $hFormat, $hBrush)

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $GUI_EVENT_RESTORE
        _GDIPlus_GraphicsDrawStringEx($hGraphic, "AutoIt Rulez !", $hFont, $aInfo[0], $hFormat, $hBrush)
      Case $idLabel
        ConsoleWrite("Label was clicked" & @CRLF)
    EndSwitch
  WEnd

  _GDIPlus_StringFormatDispose($hFormat)
  _GDIPlus_FontFamilyDispose($hFamily)
  _GDIPlus_FontDispose($hFont)
  _GDIPlus_BrushDispose($hBrush)
  _GDIPlus_GraphicsDispose($hGraphic)
  _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Edited by Nine
Posted

so the thing is that the line GUISetState() should be after the creation of the label! interesting, i never noticed it made any difference... thank you. i'll keep studying this.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted (edited)

Here my fast hack:

 

;Coded by UEZ build 2025-08-12
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGUI = GUICreate("Example", 420, 420, -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetBkColor(0xFFFFFF, $hGUI)
Global $iLabel1 = GUICtrlCreateLabel("This is a default text.", 10, 10, 300, 100)
GUICtrlSetFont(-1, 18, 400, 0, "Arial", 5)
Global $iLabel2 = GUICtrlCreatePic("", 10, 100, 300, 100)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKVCENTER, $GUI_DOCKHCENTER))
GUISetState()

_GDIPlus_BitmapCreateFadedText($iLabel2, "This is an enhanced text.")

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    _GDIPlus_BitmapCreateFadedText($iLabel2, "This is an enhanced text.")
    Return "GUI_RUNDEFMSG"
EndFunc

Func _GDIPlus_BitmapCreateFadedText($iControl, $sText, $sFont = "Arial", $fFontSize = 18, $iStartColor = 0xFF808080, $iEndColor = 0x1F0000F0, $iGradientMode = 0)
    _GDIPlus_Startup()
    Local $aSize = ControlGetPos($hGUI, "", $iControl)
    Local $hStringFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $fFontSize, 0)
    Local $aStrDim = _MeasureString($sText, $hFont, $hStringFormat, $hFamily)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($aSize[2], $aSize[3])
    Local $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
    _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 4)
    Local $tRECTF = _GDIPlus_RectFCreate(0, 0, $aStrDim[4], $aStrDim[5])
    Local $hBrush = _GDIPlus_LineBrushCreateFromRect($tRECTF, $iStartColor, $iEndColor, $iGradientMode)
    _GDIPlus_LineBrushSetGammaCorrection($hBrush, True)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, $aSize[2], $aSize[3])
    _GDIPlus_GraphicsDrawStringEx($hCanvas, $sText, $hFont, $tLayout, $hStringFormat, $hBrush)
    Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iControl, 0x0172, 0, $hHBitmap))
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCanvas)
    _GDIPlus_ImageDispose($hBitmap)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hStringFormat)
    _GDIPlus_Shutdown()
EndFunc

Func _MeasureString($sString, $hFont, $hFormat, $hFamily, $iStyle = 0)
        Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC(_WinAPI_GetDC(0))
        Local $tLayout = _GDIPlus_RectFCreate()
        Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)

        Local $aRanges[2][2] = [[1]]
        $aRanges[1][1] = StringLen($sString)
        _GDIPlus_StringFormatSetMeasurableCharacterRanges($hFormat, $aRanges)
        Local $aRegion = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphics, $sString, $hFont, $aInfo[0], $hFormat)
        Local $aBounds = _GDIPlus_RegionGetBounds($aRegion[1], $hGraphics)
        _GDIPlus_RegionDispose($aRegion[1])

        Local $iFontHeight = _GDIPlus_FontGetHeight($hFont, $hGraphics)
        Local $iLineSpacing = _GDIPlus_FontFamilyGetLineSpacing($hFamily, $iStyle)
        Local $iAscent = $iFontHeight / $iLineSpacing * _GDIPlus_FontFamilyGetCellAscent($hFamily, $iStyle)
        Local $iDescent = $iFontHeight / $iLineSpacing * _GDIPlus_FontFamilyGetCellDescent($hFamily, $iStyle)
        _GDIPlus_GraphicsDispose($hGraphics)

        Local $aDim[9]
        $aDim[0] = $aBounds[0]
        $aDim[1] = $aBounds[1]
        $aDim[2] = $aBounds[2]
        $aDim[3] = $aBounds[3]
        $aDim[4] = DllStructGetData($aInfo[0], "Width")
        $aDim[5] = DllStructGetData($aInfo[0], "Height")
        $aDim[6] = $iFontHeight
        $aDim[7] = $iAscent
        $aDim[8] = $iDescent

        Return $aDim
EndFunc   ;==>_MeasureString

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

so you are using a pic control instead of a label? functionality-wise that's fine.

how do i set the background color of the text?

the only reference to colors in the entire process seems to be in this line:

Local $hBrush = _GDIPlus_LineBrushCreateFromRect($tRECTF, $iStartColor, $iEndColor, $iGradientMode)

which refers to the gradient color edges.

 

another thing, in a resizable GUI (add the style $WS_OVERLAPPEDWINDOW), when i resize the window, there's a weird effect:

in the example by @Nine the text disappears.

in the example by @UEZ the text stretches vertically to twice its size. various docking options apply, but still the text is distorted.

 

 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted (edited)
1 hour ago, orbs said:

in the example by @Nine the text disappears.

Like I already told you, the more you ask, the more complex the code is becoming.  It is totally normal that the graphic disappears.

In this case you would need to define the label as $SS_OWNERDRAW.  Then move the graphic creation of the label in DRAWITEM window proc.

Try it, let me know if you need more help.

To set background color (previously stated) of the label, you could use 

_GDIPlus_GraphicsClear($hGraphic, 0xFFFF0000)
Edited by Nine
Posted

capturing WM_SIZE an redraw upon resize is an interesting approach.

thank you both! i'll keep fiddling with this.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted

AHH! just when i was beginning to think i understood something... 🙂

 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...