Ich habe jetzt nicht weiter rumprobiert, aber es kann durchaus sein, dass du da an die Grenzen von normalen GUI-Controls kommst. Evtl. müsstest du für so schnelles Zeichnen auf GDIPlus (ö.Ä.) ausweichen.
Ich hab mal für ein Theaterstück einen Countdown bis zum Beginn programmiert. Das war aber so eine "Es geht in einer halben Stunde los, kriegen wir das noch hin?"-Aktion, daher... Keine Resourcenfreigabe oder so. Bitte so nicht produktiv verwenden!
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
Global Const $PI = 3.141592654
Opt("GUIOnEventMode", True)
DllCall("User32.dll","bool","SetProcessDPIAware")
_GDIPlus_Startup()
;changeable
$iWndW = @DesktopWidth
$iWndH = @DesktopHeight
;end changeable
$hWnd = GUICreate("", $iWndW, $iWndH, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetOnEvent(-3, OnCloseClick)
;basic graphics
$hGfx = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBmp = _GDIPlus_BitmapCreateFromGraphics($iWndW, $iWndH, $hGfx)
$hBuf = _GDIPlus_ImageGetGraphicsContext($hBmp)
_GDIPlus_GraphicsSetSmoothingMode($hGfx, 2)
_GDIPlus_GraphicsSetSmoothingMode($hBuf, 2)
;generate watch base image
$hWatchBmp = _GDIPlus_BitmapCreateFromScan0(500, 500) ;fix, resize later
$hWatchGfx = _GDIPlus_ImageGetGraphicsContext($hWatchBmp)
_GDIPlus_GraphicsSetSmoothingMode($hWatchGfx, 2)
$hWatchPen = _GDIPlus_PenCreate(0xffffffff, 10) ;better use solid color...
$hWatchBrush = _GDIPlus_BrushCreateSolid(0xffffffff)
$hDotPen = _GDIPlus_PenCreate(0xffdddddd, 5) ;better use solid color...
_GDIPlus_GraphicsDrawEllipse($hWatchGfx, 10, 10, 480, 480, $hWatchPen)
$iInnerR = 200
$iOuterR = 240
For $i = 0 To 59 ;60 minute dots
$iOuterX = 250 + Cos((2 * $PI / 60) * $i) * ($iOuterR - 20)
$iOuterY = 250 + Sin((2 * $PI / 60) * $i) * ($iOuterR - 20)
_GDIPlus_GraphicsDrawEllipse($hWatchGfx, $iOuterX - 2, $iOuterY - 2, 4, 4, $hDotPen)
Next
For $i = 0 To 11 ;12 hour lines
$iInnerX = 250 + Cos((2 * $PI / 12) * $i) * $iInnerR
$iInnerY = 250 + Sin((2 * $PI / 12) * $i) * $iInnerR
$iOuterX = 250 + Cos((2 * $PI / 12) * $i) * $iOuterR
$iOuterY = 250 + Sin((2 * $PI / 12) * $i) * $iOuterR
_GDIPlus_GraphicsDrawLine($hWatchGfx, $iInnerX, $iInnerY, $iOuterX, $iOuterY, $hWatchPen)
Next
GUISetState()
$hPenHour = _GDIPlus_PenCreate(0xffffffff, 15)
$hPenMinute = _GDIPlus_PenCreate(0xffffffff,
$hPenSecond = _GDIPlus_PenCreate(0xffffffff, 3)
$hTimer = TimerInit()
While True
_GDIPlus_GraphicsClear($hBuf)
;input values
$iTime = TimerDiff($hTimer)
$nMilliSecond = Mod($iTime, 1000)
$nSecond = Mod($iTime / (1000), 60)
$nMinute = Mod($iTime / (1000 * 60), 60)
$nHour = $iTime / (1000 * 60 * 60)
;draw static watch image
_GDIPlus_GraphicsDrawImageRect($hBuf, $hWatchBmp, $iWndW / 2 - 250, $iWndH / 2 - 250, 500, 500)
;calculate and draw pointer
$iCenterX = $iWndW / 2
$iCenterY = $iWndH / 2
$iHourX = $iCenterX + Cos((2 * $PI / 12) * Mod($nHour, 12) - ($PI / 2)) * 150
$iHourY = $iCenterY + Sin((2 * $PI / 12) * Mod($nHour, 12) - ($PI / 2)) * 150
_GDIPlus_GraphicsDrawLine($hBuf, $iCenterX, $iCenterY, $iHourX, $iHourY, $hPenHour)
$iMinuteX = $iCenterX + Cos((2 * $PI / 60) * $nMinute - ($PI / 2)) * 190
$iMinuteY = $iCenterY + Sin((2 * $PI / 60) * $nMinute - ($PI / 2)) * 190
_GDIPlus_GraphicsDrawLine($hBuf, $iCenterX, $iCenterY, $iMinuteX, $iMinuteY, $hPenMinute)
$iSecondX = $iCenterX + Cos((2 * $PI / 60) * $nSecond - ($PI / 2)) * 230
$iSecondY = $iCenterY + Sin((2 * $PI / 60) * $nSecond - ($PI / 2)) * 230
_GDIPlus_GraphicsDrawLine($hBuf, $iCenterX, $iCenterY, $iSecondX, $iSecondY, $hPenSecond)
;draw center circle
_GDIPlus_GraphicsFillEllipse($hBuf, $iCenterX - 15, $iCenterY - 15, 30, 30, $hWatchBrush)
;draw current time in decimals
$sTime = StringFormat("%02d : %02d : %02d . %03d", $nHour, $nMinute, $nSecond, $nMilliSecond)
_GDIPlus_GraphicsDrawStringBox($hBuf, $sTime, 0, 0, "Segoe UI", 36, 0xffffffff, 1, $iWndW)
_GDIPlus_GraphicsDrawImage($hGfx, $hBmp, 0, 0)
WEnd
Func OnCloseClick()
Exit
EndFunc
Func _GDIPlus_GraphicsDrawStringBox($hGraphics, $sString, $nX, $nY, $sFont = "Arial", $nSize = 10, $iColor = 0xFF000000, $iAlignX = 0, $nW = 0.0, $iAlignY = 0, $nH = 0.0)
Local $hBrush = _GDIPlus_BrushCreateSolid($iColor)
Local $hFormat = _GDIPlus_StringFormatCreate(0)
_GDIPlus_StringFormatSetAlign($hFormat, $iAlignX)
_GDIPlus_StringFormatSetLineAlign($hFormat, $iAlignY)
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
Local $hFont = _GDIPlus_FontCreate($hFamily, $nSize)
Local $tLayout = _GDIPlus_RectFCreate($nX, $nY, $nW, $nH)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)
If @error Then Return SetError(@error, @extended, 0)
Local $aResult = _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
Local $iError = @error, $iExtended = @extended
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
Return SetError($iError, $iExtended, $aResult)
EndFunc ;==>_GDIPlus_GraphicsDrawStringBox
Alles anzeigen