Jump to content
Steurendo

[Help] Draw text on a GUI with GDIPlus.au3

Recommended Posts

Steurendo

Hi everyone!

How can i draw a simple text on a GUI with the GDIPlus.au3 library or calling GDIPlus.dll?

Thanks in advance!

Share this post


Link to post
Share on other sites
somdcomputerguy

Maybe this will get you started - _GDIPlus_FontCreate, look at the example code. Good Luck!

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
PedroWarlock

Sorry my english

Sorry for revive this topic, but i can't create a new topic Like this.

How i can drow a border and border color in this example?

Share this post


Link to post
Share on other sites
PedroWarlock

Sorry my english

Sorry for revive this topic, but i can't create a new topic Like this.

How i can drow a border and border color in this example?

Share this post


Link to post
Share on other sites
Malkey

Here is a modified _GDIPlus_FontCreate() function's example from AutoIt help file with a couple of coloured borders added.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
; Modified _GDIPlus_FontCreate() function's example from AutoIt help file.

Example()

Func Example()
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hPen1, $hPen2

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState(@SW_SHOW)

    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)

    ; Borders added to example
    $hPen1 = _GDIPlus_PenCreate(0xFFFF0000, 1, 2) ; Red colour in ARGB (hexidecimal 0xAARRGGBB)
    $hPen2 = _GDIPlus_PenCreate(0xFF0000FF, 3, 2) ; Blue colour in ARGB (hexidecimal 0xAARRGGBB)
    _GDIPlus_GraphicsDrawRect($hGraphic, 140, 110, 100, 20, $hPen1) ; Border around text
    _GDIPlus_GraphicsDrawRect($hGraphic, 3, 3, 394, 294, $hPen2) ; Inside border of 400x300 GUI

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_PenDispose($hPen1)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites
InunoTaishou

I kind of want to guess that @PedroWarlock is talking about the Stroke effect on text (like in photoshop), not a border around the bitmap?

Share this post


Link to post
Share on other sites
UEZ

Maybe something like this here!?

 

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
; Modified _GDIPlus_FontCreate() function's example from AutoIt help file.

Example()

Func Example()
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $tLayout, $hPen, $hPath

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState(@SW_SHOW)

    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_ANTIALIAS8X8)
    _GDIPlus_GraphicsSetPixelOffsetMode($hGraphic, $GDIP_PIXELOFFSETMODE_HALF)
    _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hPath = _GDIPlus_PathCreate()
    $hPen = _GDIPlus_PenCreate(0xFF303030, 4)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Impact")
    $tLayout = _GDIPlus_RectFCreate(0, 0, 400, 300)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    _GDIPlus_StringFormatSetLineAlign($hFormat, 1)
    _GDIPlus_PenSetLineJoin($hPen, 2)
    _GDIPlus_PathAddString($hPath, "Hello GDI+ World", $tLayout, $hFamily, 0, 80, $hFormat)
    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush)
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 


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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
PedroWarlock
Look at this example. I'm trying to redraw the texts in a loop, and I need to edit the text constantly and the location of the text

 

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <guiconstantsex.au3>
    Local $sWow64 = ""
If @AutoItX64 Then $sWow64 = "\Wow6432Node"
Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"
Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\Torus.png"
;--------------
    ;GUI
Global $frmMain  = GUICreate("Example", 250, 300,-1,-1,$WS_POPUP,  $WS_EX_TOPMOST)
GUISetBkColor(0xFFFFFF)
$b1=GUICtrlCreateButton("PLAY",30,250,50,50)
$b2=GUICtrlCreateButton("PAUSE",80,250,50,50)
$b3=GUICtrlCreateButton("CLEAN",130,250,50,50)
$b4=GUICtrlCreateButton("EXIT",180,250,50,50)
_GDIPlus_Startup()
;----
Global $hGraphic   = _GDIPlus_GraphicsCreateFromHWND($frmMain)
Global $hBitmap    = _GDIPlus_BitmapCreateFromGraphics(250, 250, $hGraphic)
Global $hBuffer    = _GDIPlus_ImageGetGraphicsContext($hBitmap)
;background
    $hImageBg      = _GDIPlus_ImageLoadFromFile($sFile)
;Text 2
    $hBrush_preto  = _GDIPlus_BrushCreateSolid(0xFF000000)
    $hFormat       = _GDIPlus_StringFormatCreate()
    $hFamily       = _GDIPlus_FontFamilyCreate("Arial")
    $hFont         = _GDIPlus_FontCreate($hFamily, 25, 1)
    $tLayout       = _GDIPlus_RectFCreate(0, 20, 230, 0)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    
;Text 1
    $hPath            = _GDIPlus_PathCreate()
    $hPen_white    = _GDIPlus_PenCreate(0xFF303030, 4)
    $tLayout2      = _GDIPlus_RectFCreate(0, 130, 230, 0)
    $count=0
    ;-------------------
GUISetState(@SW_SHOW, $frmMain)
;~ _WinAPI_SetLayeredWindowAttributes($frmMain, 0xFFFFFF, 0xFF)
    
$play=False
    While(True)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE,$b4
            Exit
        Case $b1
            $play=true
        Case $b2
            $play=False
        Case $b3
            $count=0
    EndSwitch
            ; clean
            _GDIPlus_GraphicsClear($hBuffer,0xFFFFFFFF)
            ; draw background
            _GDIPlus_GraphicsDrawImage($hBuffer, $hImageBg, 0, 0)
                ; Texto - Type 1
            _GDIPlus_PathAddString($hPath, "Text 1" & @CRLF & $somando, $tLayout2, $hFamily, 1, 50, $hFormat)
            _GDIPlus_GraphicsFillPath($hBuffer, $hPath, $hBrush_preto)
            _GDIPlus_GraphicsDrawPath($hBuffer, $hPath, $hPen_white)
               ; Texto - Type 2
            _GDIPlus_GraphicsDrawStringEx($hBuffer, "Text 2" & @CRLF & $count, $hFont, $tLayout, $hFormat,  $hBrush_preto)
    
            _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
if $play Then $count+=1
    WEnd
Edited by PedroWarlock

Share this post


Link to post
Share on other sites

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

×