Here's my version of the same clock. It's probably been done before and the code's a bit messy but I thought I'd post it here anyway in case anyone has a use for it. I'm not sure who wrote the function for _GDIPlus_CreateLineBrushFromRect but I took it from this post by monoceres. In fact, that code was my starting point for the clock
#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) Global $clockSize = InputBox("Clock", "How big?", 240) If @error Or (Number($clockSize) = 0) Then Exit Global $hWnd = GUICreate("Clock", $clockSize, $clockSize) GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitClock") _GDIPlus_Startup() Global $graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) Global $bitmap = _GDIPlus_BitmapCreateFromGraphics($clockSize, $clockSize, $graphics) Global $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4) AdlibEnable("_DrawClock", 200) Global $lgBrush = _GDIPlus_CreateLineBrushFromRect(20, 20, $clockSize - 10, $clockSize - 10, -1, -1, 0xFF7878FF, 0xFF000000, 0) Global $irBrush = _GDIPlus_CreateLineBrushFromRect(20, 20, $clockSize - 10, $clockSize - 10, -1, -1, 0xFF000000, 0xFF7878FF, 0) Global $nuBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("Arial") Global $nuFont = _GDIPlus_FontCreate($hFamily, $clockSize / 20, 1) Global $hourBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Global $minuteBrush = _GDIPlus_BrushCreateSolid(0xFFD0D0D0) Global $secondPen = _GDIPlus_PenCreate(0xFFFF0000, 1) Global $bitmap2 = _GDIPlus_BitmapCreateFromGraphics($clockSize, $clockSize, $graphics) Global $backbuffer2 = _GDIPlus_ImageGetGraphicsContext($bitmap2) _GDIPlus_GraphicsSetSmoothingMode($backbuffer2, 4) _GDIPlus_GraphicsClear($backbuffer2, 0xFFFFFFFF) _GDIPlus_GraphicsFillEllipse($backbuffer2, 20, 20, $clockSize - 40, $clockSize - 40, $lgBrush) _GDIPlus_GraphicsFillEllipse($backbuffer2, 30, 30, $clockSize - 60, $clockSize - 60, $irBrush) _GDIPlus_GraphicsFillEllipse($backbuffer2, 33, 33, $clockSize - 66, $clockSize - 66, $lgBrush) For $i = 1 To 12 _DrawNumber($i) Next GUIRegisterMsg($WM_PAINT, "MY_PAINT") GUISetState() Do Until Not Sleep(100) Func MY_PAINT($hWnd, $uMsg, $lParam, $wParam) _DrawClock() Return $GUI_RUNDEFMSG EndFunc ;==>MY_PAINT Func _DrawClock() _GDIPlus_GraphicsDrawImage($backbuffer, $bitmap2, 0, 0) Local $secondAngle = 8.0 * ATan(1) * @SEC / 60.0 Local $minuteAngle = 8.0 * ATan(1) * (@MIN + @SEC / 60.0) / 60.0 Local $hourAngle = 8.0 * ATan(1) * (@HOUR + @MIN / 60.0) / 12.0 Local $HandsWidth = $clockSize / 48 Local $HourArrowSize = $clockSize / 2 - 80 Local $HourArrow[5][2] = [[4, 0], _ [Int($HourArrowSize * Sin($hourAngle)) + $clockSize / 2, Int(-$HourArrowSize * Cos($hourAngle)) + $clockSize / 2], _ [Int(-$HandsWidth * Cos($hourAngle)) + $clockSize / 2, Int(-$HandsWidth * Sin($hourAngle)) + $clockSize / 2], _ [Int($HandsWidth * Cos($hourAngle)) + $clockSize / 2, Int($HandsWidth * Sin($hourAngle)) + $clockSize / 2], _ [Int($HourArrowSize * Sin($hourAngle)) + $clockSize / 2, Int(-$HourArrowSize * Cos($hourAngle)) + $clockSize / 2]] _GDIPlus_GraphicsFillPolygon($backbuffer, $HourArrow, $hourBrush) Local $MinuteArrowSize = $clockSize / 2 - 50 Local $MinuteArrow[5][2] = [[4, 0], _ [Int($MinuteArrowSize * Sin($minuteAngle)) + $clockSize / 2, Int(-$MinuteArrowSize * Cos($minuteAngle)) + $clockSize / 2], _ [Int(-$HandsWidth* Cos($minuteAngle)) + $clockSize / 2, Int(-$HandsWidth * Sin($minuteAngle)) + $clockSize / 2], _ [Int($HandsWidth * Cos($minuteAngle)) + $clockSize / 2, Int($HandsWidth * Sin($minuteAngle)) + $clockSize / 2], _ [Int($MinuteArrowSize * Sin($minuteAngle)) + $clockSize / 2, Int(-$MinuteArrowSize * Cos($minuteAngle)) + $clockSize / 2]] _GDIPlus_GraphicsFillPolygon($backbuffer, $MinuteArrow, $minuteBrush) _GDIPlus_GraphicsFillEllipse($backbuffer, $clockSize / 2 - $HandsWidth, $clockSize / 2 - $HandsWidth, $HandsWidth * 2, $HandsWidth * 2, $minuteBrush) Local $SecondHandSize = $MinuteArrowSize _GDIPlus_GraphicsDrawLine($backbuffer, $clockSize / 2, $clockSize / 2, Int($SecondHandSize * Sin($secondAngle)) + $clockSize / 2, _ Int(-$SecondHandSize * Cos($secondAngle)) + $clockSize / 2, $secondPen) _GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0) EndFunc ;==>_DrawClock Func _DrawNumber($nDigit) Local $hourAngle = 8 * ATan(1) * $nDigit / 12 Local $x = Int(($clockSize / 2 - 50) * Sin($hourAngle)) + $clockSize / 2 Local $y = Int(-($clockSize / 2 - 50) * Cos($hourAngle)) + $clockSize / 2 Local $tLayout = _GDIPlus_RectFCreate($x, $y) Local $aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, String($nDigit), $nuFont, $tLayout, $hFormat) DllStructSetData($aInfo[0], 1, $x - DllStructGetData($aInfo[0], 3) / 2) DllStructSetData($aInfo[0], 2, $y - DllStructGetData($aInfo[0], 4) / 2) _GDIPlus_GraphicsDrawStringEx($backbuffer2, String($nDigit), $nuFont, $aInfo[0], $hFormat, $nuBrush) EndFunc ;==>_DrawNumber Func _ExitClock() _GDIPlus_GraphicsDispose($backbuffer2) _GDIPlus_BitmapDispose($bitmap2) _GDIPlus_PenDispose($secondPen) _GDIPlus_BrushDispose($minuteBrush) _GDIPlus_BrushDispose($hourBrush) _GDIPlus_FontDispose($nuFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($nuBrush) _GDIPlus_BrushDispose($irBrush) _GDIPlus_BrushDispose($lgBrush) _GDIPlus_GraphicsDispose($backbuffer) _GDIPlus_BitmapDispose($bitmap) _GDIPlus_GraphicsDispose($graphics) _GDIPlus_Shutdown() Exit EndFunc ;==>_ExitClock ;==== GDIPlus_CreateLineBrushFromRect === ;Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors. ; $aFactors - If non-array, default array will be used. ; Pointer to an array of real numbers that specify blend factors. Each number in the array ; specifies a percentage of the ending color and should be in the range from 0.0 through 1.0. ;$aPositions - If non-array, default array will be used. ; Pointer to an array of real numbers that specify blend factors' positions. Each number in the array ; indicates a percentage of the distance between the starting boundary and the ending boundary ; and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the ; gradient and 1.0 indicates the ending boundary. There must be at least two positions ; specified: the first position, which is always 0.0, and the last position, which is always ; 1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a ; line, parallel to the boundary lines, that is a certain fraction of the distance from the ; starting boundary to the ending boundary. For example, a blend position of 0.7 indicates ; the line that is 70 percent of the distance from the starting boundary to the ending boundary. ; The color is constant on lines that are parallel to the boundary lines. ; $iArgb1 - First Top color in 0xAARRGGBB format ; $iArgb2 - Second color in 0xAARRGGBB format ; $LinearGradientMode - LinearGradientModeHorizontal = 0x00000000, ; LinearGradientModeVertical = 0x00000001, ; LinearGradientModeForwardDiagonal = 0x00000002, ; LinearGradientModeBackwardDiagonal = 0x00000003 ; $WrapMode - WrapModeTile = 0, ; WrapModeTileFlipX = 1, ; WrapModeTileFlipY = 2, ; WrapModeTileFlipXY = 3, ; WrapModeClamp = 4 ; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2, ; LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient) ; Reference: http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx ; Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _ $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0) Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000 If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001 If $WrapMode = -1 Then $WrapMode = 1 $tRect = DllStructCreate("float X;float Y;float Width;float Height") $pRect = DllStructGetPtr($tRect) DllStructSetData($tRect, "X", $iX) DllStructSetData($tRect, "Y", $iY) DllStructSetData($tRect, "Width", $iWidth) DllStructSetData($tRect, "Height", $iHeight) ;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _ "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0) If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0] If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0] $iCount = UBound($aPositions) $tFactors = DllStructCreate("float[" & $iCount & "]") $pFactors = DllStructGetPtr($tFactors) For $iI = 0 To $iCount - 1 DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1) Next $tPositions = DllStructCreate("float[" & $iCount & "]") $pPositions = DllStructGetPtr($tPositions) For $iI = 0 To $iCount - 1 DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1) Next Local $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _ "ptr", $pFactors, "ptr", $pPositions, "int", $iCount) Return $aRet[6]; Handle of Line Brush EndFunc ;==>_GDIPlus_CreateLineBrushFromRect
EDIT: Used ProgAndy's code and changed it a bit to make the size configurable. Also changed the hard-coded positioning of the numerals in favour of calculating them.
WBD
Edited by WideBoyDixon, 14 May 2009 - 04:22 PM.







