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