Jump to content
Sign in to follow this  

Refresh a GDI string?

Recommended Posts

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>

Until @Sec = 0

Func Clock()

 Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
 $hour = @HOUR
 $min= @MIN
 $ellipses= ":"
 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

    If @MIN <> $min Then $min = @MIN
    If @HOUR <> $Hour Then $Hour = @HOUR
    If $hour >12 Then $hour = @Hour - 12
    ; Draw a string
    $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)
;~  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


Share this post

Link to post
Share on other sites

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



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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...