Sign in to follow this  
Followers 0
allSystemsGo

Refresh a GDI string?

3 posts in this topic

I am trying (emphasis on trying) to create a simple clock in autoit. I thought, hey, would be a good time to use GDI.

How do I refresh a GDI string? For example, when the minute updates, actually put the new data for the minute in the gui.

Here is my code so far

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>


Do
Until @Sec = 0
clock()

Func Clock()


 Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
 $hour = @HOUR
 $min= @MIN
 $ellipses= ":"
 $timeOfDay="AM"
 $seconds=@SEC
 If $hour >12 then $timeOfDay = "PM"
 If $hour >12 Then $hour = @Hour - 12
    Local $sHour = $hour, $aInfo
    Local $sEllipses = $ellipses, $bInfo
    Local $sMin= $min, $cInfo
    Local $sTimeOfDay= $timeOfDay, $dInfo
    $hGUI = GUICreate("GDI+", 400, 300)

While 1
    ; Create GUI

    GUISetState(@SW_SHOW)
    If @MIN <> $min Then $min = @MIN
    If @HOUR <> $Hour Then $Hour = @HOUR
    If $hour >12 Then $hour = @Hour - 12
    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Calibri")
    $hFont = _GDIPlus_FontCreate($hFamily, 18, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 0, 0)
    $uLayout=_GDIPlus_RectFCreate(180, 110, 0, 0)
    $vLayout=_GDIPlus_RectFCreate(210, 110, 0, 0)
    $wLayout=_GDIPlus_RectFCreate(240, 110, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sHour, $hFont, $tLayout, $hFormat)
    $bInfo= _GDIPlus_GraphicsMeasureString($hGraphic, $sEllipses, $hFont, $uLayout, $hFormat)
    $cInfo=_GDIPlus_GraphicsMeasureString($hGraphic, $sMin, $hFont, $vLayout, $hFormat)
    $dInfo=_GDIPlus_GraphicsMeasureString($hGraphic, $sTimeOfDay, $hFont, $wLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sHour, $hFont, $aInfo[0], $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sEllipses, $hFont, $bInfo[0], $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sMin, $hFont, $cInfo[0], $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sTimeOfDay, $hFont, $dInfo[0], $hFormat, $hBrush)
    sleep(60000)
;~  If @MIN <> $min Then $min = @MIN
;~  _GDIPlus_GraphicsDrawStringEx($hGraphic, $sMin, $hFont, $cInfo[0], $hFormat, $hBrush)
;~  If @HOUR <> $Hour Then $Hour = @HOUR
;~  If $hour >12 Then $hour = @Hour - 12
;~  _GDIPlus_GraphicsDrawStringEx($hGraphic, $sHour, $hFont, $aInfo[0], $hFormat, $hBrush)

;~  GUIDelete($hGraphic)




    ; 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_Shutdown()
Wend

EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Search the forum for "gdiplus clock time" for many examples.

Br,

UEZ

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

I finally got it working then found out that GDI doesnt render in RDP environment. :censored:

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
Sign in to follow this  
Followers 0