Liebe AutoIt-Gemeinde, liebe Experten,
ich bin relativ neu im AutoIt-Gewerbe. Falls ich also etwas Offensichtliches übersehen haben sollte, so bitte ich um Nachsicht.
Vorab: Als Testumgebung nutze ich noch Windows XP (SP3) - und kann dies auch nicht unmittelbar ändern (falls dies eine Rolle spielen sollt.
Ich schreibe mir selbst einen Countdown-Timer (unter Zuhilfenahme verschiedener Programmierbeispiele aus AutoIt-Foren). Diese Countdown-Uhr soll mit transparentem Hintergrund unbeweglich in der rechten, unteren Ecke des Bildschirms liegen (TOPMOST, aber inaktiv als Fenster) und eine voreingestellte Anzahl an Minuten herunterzählen, um beim Erreichen von 0 Minuten und Sekunden zu verschwinden.
Das funktioniert soweit ganz gut, aber ich habe bei jedem Ändern der Sekunden/Minuten/Stunden ein kurzes Flackern, das ich einfach nicht wegbekomme.
Hier der - der Übersichtlichkeit halber etwas vereinfachte - Code:
[autoit]#include <GuiConstants.au3>
#include <GuiconstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Dim $nowmins, $nowhours, $nowsecs
Dim $countmins, $counthours, $countsecs
Dim $timermins, $timerhours, $timersecs
Dim $endtime, $jetztzeit, $startzeit, $nettozeit
Dim $relzeit, $relseconds, $relminutes, $relhours
Dim $greenhx
$greenhx = 0x72C45C
$timerhours = 0
$timermins = 5
$timersecs = 0
$nowhours = @HOUR
$nowmins = @Min
$nowsecs = @SEC
$countsecs = $nowsecs + $timersecs
$countmins = $nowmins + $timermins
$counthours = $nowhours + $timerhours
If $countsecs > 59 Then
$countsecs = $countsecs - 60
$countmins = $countmins + 1
EndIf
If $countmins > 59 Then
$countmins = $countmins - 60
$counthours = $counthours + 1
EndIf
If $counthours > 23 Then
Exit
EndIf
$startzeit = ($nowhours * 3600) + ($nowmins * 60) + $nowsecs
$endtime = ($counthours * 3600) + ($countmins * 60) + $countsecs
$nettozeit = ($timerhours * 3600) + ($timermins * 60) + $timersecs
$Form1 = GUICreate("Form1", 120, 35, @DesktopWidth -120, @DesktopHeight -35, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))
[/autoit][autoit][/autoit][autoit]GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($Form1, 0xABCDEF, 255)
$jetztzeit = (@HOUR * 3600) + (@Min * 60) + @Sec
$relhours = Floor(($endtime - $jetztzeit) / 3600)
$relminutes = Floor((($endtime - $jetztzeit) - ($relhours * 3600)) /60)
$relseconds = Floor(($endtime - $jetztzeit) - ($relhours * 3600) - ($relminutes * 60))
$Label_3 = GUICtrlCreateLabel(StringFormat("%02u", $relminutes), 38, 0, 100, 30)
$Label_4 = GUICtrlCreateLabel(":", 66, 0, 100, 30)
$Label_5 = GUICtrlCreateLabel(StringFormat("%02u", $relseconds), 76, 0, 100, 30)
GUICtrlSetFont ( $Label_3, 20, 800, 0, "Arial")
GUICtrlSetColor( $Label_3, $greenhx)
GUICtrlSetFont ( $Label_4, 20, 800, 0, "Arial")
GUICtrlSetColor( $Label_4, $greenhx)
GUICtrlSetFont ( $Label_5, 20, 800, 0, "Arial")
GUICtrlSetColor( $Label_5, $greenhx)
GUISetState()
[/autoit][autoit][/autoit][autoit]While ( $jetztzeit <= $endtime)
$msg = GUIGetMsg()
Select Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case Else
$relzeit = $endtime - $jetztzeit
GUICtrlSetData($Label_3, StringFormat("%02u", $relminutes))
GUICtrlSetColor( $Label_3, $greenhx)
GUICtrlSetFont ( $Label_3, 20, 800, 0, "Arial")
GUICtrlSetData($Label_5, StringFormat("%02u", $relseconds))
GUICtrlSetColor( $Label_5, $greenhx)
GUICtrlSetFont ( $Label_5, 20, 800, 0, "Arial")
GuiSetState()
Sleep(100) ; 100 gesetzt, um das Flackern deutlich zu machen
$jetztzeit = (@HOUR * 3600) + (@Min * 60) + @Sec
$relhours = Floor(($endtime - $jetztzeit) / 3600)
$relminutes = Floor((($endtime - $jetztzeit) - ($relhours * 3600)) /60)
$relseconds = Floor(($endtime - $jetztzeit) - ($relhours * 3600) - ($relminutes * 60))
EndSelect
WEnd
Exit
[/autoit]Die Vereinfachungen betreffen u.a. die Anzeige der Stunden, einen Farbwechsel bei Erreichen einer Restzeit x, das Ermitteln des aktiven Fensters vor GUICreate und Rückgabe der Aktivierung an dasselbe Fenster danach, die Übergabe der Zeit per Kommandozeile, etc... also alles schnickschnack, der nichts zur Problemlösung beiträgt, aber das Skript schwerer lesbar macht.
Das Problem ist: Jede Aktualisierung der Zahlen lässt die GUI "flackern".
Kann mir jemand hier helfen? Wie bekomme ich dieses Flackern weg ohne sonstige Funktionalität zu verlieren?
Danke vielmals vorab.
Oliver
EDIT: CrLf im Code hinzugefügt...