Jump to content

Clock in GDI+


Recommended Posts

I'm just starting to poke around with GDI+ and so I set myself the task of re-creating some code that I found here: http://www.publicjoe.f9.co.uk/vbnet/tut/vbnet16.html

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
Link to comment
Share on other sites

  • Moderators

Nice Job. I'm impressed with how that turned out... Not a fan of the 25% CPU usage, but it's understood.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Really impressive WideBoyDixon. I was able to make some CPU usage optimizations, e.g. I moved the painting of the background to an other buffer bitmap and increased the interval fpr redrawing :)

; all credits to WideBoyDixon, i just reordered his code.
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)
$width = 240
$height = 240
$hWnd = GUICreate("Clock", $width, $height)

GUISetOnEvent($GUI_EVENT_CLOSE, "close")


_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)

$inc = 0
AdlibEnable("_DrawClock",200)
$lgBrush = _GDIPlus_CreateLineBrushFromRect(20, 20, 230, 230, -1, -1, 0xFF7878FF, 0xFF000000, 0)
$irBrush = _GDIPlus_CreateLineBrushFromRect(20, 20, 230, 230, -1, -1, 0xFF000000, 0xFF7878FF, 0)
$nuBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$nuFont = _GDIPlus_FontCreate($hFamily, 12, 1)

$hourBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$minuteBrush = _GDIPlus_BrushCreateSolid(0xFFD0D0D0)
$secondPen = _GDIPlus_PenCreate(0xFFFF0000, 1)

$bitmap2 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer2 = _GDIPlus_ImageGetGraphicsContext($bitmap2)

_GDIPlus_GraphicsSetSmoothingMode($backbuffer2, 4)
    _GDIPlus_GraphicsClear($backbuffer2, 0xFFFFFFFF)

    _GDIPlus_GraphicsFillEllipse($backbuffer2, 20, 20, 200, 200, $lgBrush)
    _GDIPlus_GraphicsFillEllipse($backbuffer2, 30, 30, 180, 180, $irBrush)
    _GDIPlus_GraphicsFillEllipse($backbuffer2, 33, 33, 174, 174, $lgBrush)

    _DrawMyText("12", 109, 40)
    _DrawMyText("11", 75, 50)
    _DrawMyText("10", 47, 75)
    _DrawMyText("9", 43, 110)
    _DrawMyText("8", 52, 145)
    _DrawMyText("7", 75, 170)
    _DrawMyText("6", 113, 180)
    _DrawMyText("5", 150, 170)
    _DrawMyText("4", 173, 145)
    _DrawMyText("3", 182, 110)
    _DrawMyText("2", 173, 75)
    _DrawMyText("1", 150, 50)

GUIRegisterMsg($WM_PAINT,"MY_PAINT")
GUISetState()
Do


Until Not Sleep(100)
Func MY_PAINT($hWnd,$uMsg,$lParam,$wParam)
    _DrawClock()
    Return $GUI_RUNDEFMSG
EndFunc
Func _DrawClock()
    _GDIPlus_GraphicsDrawImage($backbuffer,$bitmap2,0,0)
    ;Create angles
    $secondAngle = 8.0 * ATan(1) * @SEC / 60.0
    $minuteAngle = 8.0 * ATan(1) * (@MIN + @SEC / 60.0) / 60.0
    $hourAngle = 8.0 * ATan(1) * (@HOUR + @MIN / 60.0) / 12.0

    ;Draw Hour Hand
    Local $HourArrow[5][2] = [[4, 0], _
            [Int(40 * Sin($hourAngle)) + 120, Int(-40 * Cos($hourAngle)) + 120], _
            [Int(-5 * Cos($hourAngle)) + 120, Int(-5 * Sin($hourAngle)) + 120], _
            [Int(5 * Cos($hourAngle)) + 120, Int(5 * Sin($hourAngle)) + 120], _
            [Int(40 * Sin($hourAngle)) + 120, Int(-40 * Cos($hourAngle)) + 120]]

    _GDIPlus_GraphicsFillPolygon($backbuffer, $HourArrow, $hourBrush)
;~     _GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $hourBrush)

    Local $MinuteArrow[5][2] = [[4, 0], _
            [Int(70 * Sin($minuteAngle)) + 120, Int(-70 * Cos($minuteAngle)) + 120], _
            [Int(-5 * Cos($minuteAngle)) + 120, Int(-5 * Sin($minuteAngle)) + 120], _
            [Int(5 * Cos($minuteAngle)) + 120, Int(5 * Sin($minuteAngle)) + 120], _
            [Int(70 * Sin($minuteAngle)) + 120, Int(-70 * Cos($minuteAngle)) + 120]]

    _GDIPlus_GraphicsFillPolygon($backbuffer, $MinuteArrow, $minuteBrush)
    _GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $minuteBrush)

    _GDIPlus_GraphicsDrawLine($backbuffer, 120, 120, Int(70 * Sin($secondAngle)) + 120, _
            Int(-70 * Cos($secondAngle)) + 120, $secondPen)

    _GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0)
EndFunc

Func _DrawMyText($text, $x, $y)
    $tLayout = _GDIPlus_RectFCreate($x, $y)
    $aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont, $aInfo[0], $hFormat, $nuBrush)
EndFunc   ;==>_DrawMyText

Func close()
    _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   ;==>close

;==== 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

    $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
            "ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
    Return $aRet[6]; Handle of Line Brush
EndFunc   ;==>_GDIPlus_CreateLineBrushFromRect
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

It looks very nice wbd, and its veru easy to use to, It's taken me about 2 mins to figure out the script and make a few changes to my liking. The only real concern I have is the amount of cpu it takes up... What I added was that you can choose to show/not show certain hands... It just makes it easier for me.

CODE
; all credits to WideBoyDixon, i just reordered his code.

#include <WindowsConstants.au3>

#include <GUIConstantsEx.au3>

#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

$width = 240

$height = 240

$hWnd = GUICreate("Clock", $width, $height)

$Context = GUICtrlCreateContextMenu (-1)

Global $ShowSec = GUICtrlCreateMenuItem ("Hide Sec", $Context)

GUICtrlSetOnEvent ($ShowSec, "_Sec")

Global $ShowMin = GUICtrlCreateMenuItem ("Hide Min", $Context)

GUICtrlSetOnEvent ($ShowMin, "_Min")

Global $ShowHour = GUICtrlCreateMenuItem ("Hide Hour", $Context)

GUICtrlSetOnEvent ($ShowHour, "_Hour")

GUISetOnEvent($GUI_EVENT_CLOSE, "close")

GUISetState()

Global $sShow = 1

Global $mShow = 1

Global $hShow = 1

_GDIPlus_Startup()

$graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)

$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)

$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)

$inc = 0

AdlibEnable("_DrawClock",200)

$lgBrush = _GDIPlus_CreateLineBrushFromRect(20, 20, 230, 230, -1, -1, 0xFF7878FF, 0xFF000000, 0)

$irBrush = _GDIPlus_CreateLineBrushFromRect(20, 20, 230, 230, -1, -1, 0xFF000000, 0xFF7878FF, 0)

$nuBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

$hFormat = _GDIPlus_StringFormatCreate()

$hFamily = _GDIPlus_FontFamilyCreate("Arial")

$nuFont = _GDIPlus_FontCreate($hFamily, 12, 1)

$hourBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

$minuteBrush = _GDIPlus_BrushCreateSolid(0xFFD0D0D0)

$secondPen = _GDIPlus_PenCreate(0xFFFF0000, 1)

$bitmap2 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)

$backbuffer2 = _GDIPlus_ImageGetGraphicsContext($bitmap2)

_GDIPlus_GraphicsSetSmoothingMode($backbuffer2, 4)

_GDIPlus_GraphicsClear($backbuffer2, 0xFFFFFFFF)

_GDIPlus_GraphicsFillEllipse($backbuffer2, 20, 20, 200, 200, $lgBrush)

_GDIPlus_GraphicsFillEllipse($backbuffer2, 30, 30, 180, 180, $irBrush)

_GDIPlus_GraphicsFillEllipse($backbuffer2, 33, 33, 174, 174, $lgBrush)

_DrawMyText("12", 109, 40)

_DrawMyText("11", 75, 50)

_DrawMyText("10", 47, 75)

_DrawMyText("9", 43, 110)

_DrawMyText("8", 52, 145)

_DrawMyText("7", 75, 170)

_DrawMyText("6", 113, 180)

_DrawMyText("5", 150, 170)

_DrawMyText("4", 173, 145)

_DrawMyText("3", 182, 110)

_DrawMyText("2", 173, 75)

_DrawMyText("1", 150, 50)

GUIRegisterMsg($WM_PAINT,"MY_PAINT")

GUISetState()

Do

Until Not Sleep(100)

Func MY_PAINT($hWnd,$uMsg,$lParam,$wParam)

_DrawClock()

Return $GUI_RUNDEFMSG

EndFunc

Func _DrawClock()

_GDIPlus_GraphicsDrawImage($backbuffer,$bitmap2,0,0)

;Create angles

$secondAngle = 8.0 * ATan(1) * @SEC / 60.0

$minuteAngle = 8.0 * ATan(1) * (@MIN + @SEC / 60.0) / 60.0

$hourAngle = 8.0 * ATan(1) * (@HOUR + @MIN / 60.0) / 12.0

;Draw Hour Hand

If $hShow = 1 Then

Local $HourArrow[5][2] = [[4, 0], _

[int(40 * Sin($hourAngle)) + 120, Int(-40 * Cos($hourAngle)) + 120], _

[int(-5 * Cos($hourAngle)) + 120, Int(-5 * Sin($hourAngle)) + 120], _

[int(5 * Cos($hourAngle)) + 120, Int(5 * Sin($hourAngle)) + 120], _

[int(40 * Sin($hourAngle)) + 120, Int(-40 * Cos($hourAngle)) + 120]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $HourArrow, $hourBrush)

;~ _GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $hourBrush)

EndIf

If $mShow = 1 Then

Local $MinuteArrow[5][2] = [[4, 0], _

[int(70 * Sin($minuteAngle)) + 120, Int(-70 * Cos($minuteAngle)) + 120], _

[int(-5 * Cos($minuteAngle)) + 120, Int(-5 * Sin($minuteAngle)) + 120], _

[int(5 * Cos($minuteAngle)) + 120, Int(5 * Sin($minuteAngle)) + 120], _

[int(70 * Sin($minuteAngle)) + 120, Int(-70 * Cos($minuteAngle)) + 120]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $MinuteArrow, $minuteBrush)

_GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $minuteBrush)

EndIf

If $sShow = 1 Then

_GDIPlus_GraphicsDrawLine($backbuffer, 120, 120, Int(70 * Sin($secondAngle)) + 120, _

Int(-70 * Cos($secondAngle)) + 120, $secondPen)

EndIf

_GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0)

EndFunc

Func _DrawMyText($text, $x, $y)

$tLayout = _GDIPlus_RectFCreate($x, $y)

$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont, $tLayout, $hFormat)

_GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont, $aInfo[0], $hFormat, $nuBrush)

EndFunc ;==>_DrawMyText

Func close()

_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 ;==>close

;==== 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

$hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _

"ptr", $pFactors, "ptr", $pPositions, "int", $iCount)

Return $aRet[6]; Handle of Line Brush

EndFunc ;==>_GDIPlus_CreateLineBrushFromRect

Func _Sec ()

If $sShow = 1 Then

GUICtrlSetData ($ShowSec, "Show Sec")

$sShow = 0

Else

GUICtrlSetData ($ShowSec, "Hide Sec")

$sShow = 1

EndIf

EndFunc ; ==> _Sec

Func _Min ()

If $mShow = 1 Then

GUICtrlSetData ($ShowMin, "Show Min")

$mShow = 0

Else

GUICtrlSetData ($ShowMin, "Hide Min")

$mShow = 1

EndIf

EndFunc ; ==> _Min

Func _Hour ()

If $hShow = 1 Then

GUICtrlSetData ($ShowHour, "Show Hour")

$hShow = 0

Else

GUICtrlSetData ($ShowHour, "Hide Hour")

$hShow = 1

EndIf

EndFunc ; ==> _Hour

If I can find a way to bring the cpu down to thats of a program like clocx, then It will be definitely something I use a lot! Thanks wbd.

MDiesel

Edit: Now using ProgAndys code - a huge improvement!!

Edited by mdiesel
Link to comment
Share on other sites

Actually, I never looked at the CPU usage. I guess the sleep could be increased to something a bit more palatable like 200 or so.

WBD

Link to comment
Share on other sites

It's very nice. I'll probaly try to get the size reduced and add a transparent background for running it on my desktop.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi!

Very nice, WideBoyDixon !

I modified (just a little), for transparency (like a widget/gadget):

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
$width = 230
$height = 230
GUISetBkColor(0x888822)
$hWnd = GUICreate("Clock", $width, $height, 1, 1)
GUISetBkColor(0xFF2222)
GUISetStyle($WS_POPUP,$WS_EX_LAYERED, $hWnd)
_WinAPI_SetLayeredWindowAttributes($hWnd, 0xFF2222)

GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)

$inc = 0

$lgBrush = _GDIPlus_CreateLineBrushFromRect(0, 0, $width, $width, -1, -1, 0xFF7878FF, 0xFF000000, 0)
$irBrush = _GDIPlus_CreateLineBrushFromRect(0, 0, $width, $width, -1, -1, 0xFF000000, 0xFF7878FF, 0)
$nuBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$nuFont = _GDIPlus_FontCreate($hFamily, 12, 1)

$hourBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFEE)
$minuteBrush = _GDIPlus_BrushCreateSolid(0xFFD0D0D0)
$secondPen = _GDIPlus_PenCreate(0xFFFF0000, 1)


Do
;_GDIPlus_GraphicsClear($backbuffer, 0xFFFFFFF0)

_GDIPlus_GraphicsFillEllipse($backbuffer, 20, 20, $width-30, $height-30, $lgBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer, 30, 30, $width-30-20, $height-30-20, $irBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer, 33, 33, $width-30-20-6, $height-30-20-6, $lgBrush)

_DrawMyText("12", 109, 40)
_DrawMyText("11", 75, 50)
_DrawMyText("10", 47, 75)
_DrawMyText("9", 43, 110)
_DrawMyText("8", 52, 145)
_DrawMyText("7", 75, 170)
_DrawMyText("6", 113, 180)
_DrawMyText("5", 150, 170)
_DrawMyText("4", 173, 145)
_DrawMyText("3", 182, 110)
_DrawMyText("2", 173, 75)
_DrawMyText("1", 150, 50)

;Create angles
$secondAngle = 8.0 * ATan(1) * @SEC / 60.0
$minuteAngle = 8.0 * ATan(1) * (@MIN + @SEC / 60.0) / 60.0
$hourAngle = 8.0 * ATan(1) * (@HOUR + @MIN / 60.0) / 12.0

;Draw Hour Hand
Local $HourArrow[5][2] = [[4, 0], _
[Int(40 * Sin($hourAngle)) + 120, Int(-40 * Cos($hourAngle)) + 120], _
[Int(-5 * Cos($hourAngle)) + 120, Int(-5 * Sin($hourAngle)) + 120], _
[Int(5 * Cos($hourAngle)) + 120, Int(5 * Sin($hourAngle)) + 120], _
[Int(40 * Sin($hourAngle)) + 120, Int(-40 * Cos($hourAngle)) + 120]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $HourArrow, $hourBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $hourBrush)

Local $MinuteArrow[5][2] = [[4, 0], _
[Int(70 * Sin($minuteAngle)) + 120, Int(-70 * Cos($minuteAngle)) + 120], _
[Int(-5 * Cos($minuteAngle)) + 120, Int(-5 * Sin($minuteAngle)) + 120], _
[Int(5 * Cos($minuteAngle)) + 120, Int(5 * Sin($minuteAngle)) + 120], _
[Int(70 * Sin($minuteAngle)) + 120, Int(-70 * Cos($minuteAngle)) + 120]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $MinuteArrow, $minuteBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $minuteBrush)

_GDIPlus_GraphicsDrawLine($backbuffer, 120, 120, Int(70 * Sin($secondAngle)) + 120, _
Int(-70 * Cos($secondAngle)) + 120, $secondPen)

_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
Until Not Sleep(20)
Exit


Func _DrawMyText($text, $x, $y)
$tLayout = _GDIPlus_RectFCreate($x, $y)
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer, $text, $nuFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($backbuffer, $text, $nuFont, $aInfo[0], $hFormat, $nuBrush)
EndFunc;==>_DrawMyText

Func close()
_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;==>close

;==== 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: [url="http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx"]http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx[/url]
;
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

$hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
"ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
Return $aRet[6]; Handle of Line Brush
EndFunc;==>_GDIPlus_CreateLineBrushFromRect




Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
If Not $isColorRef Then
$i_transcolor = Hex(String($i_transcolor), 6)
$i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
EndIf
Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
Select
Case @error
Return SetError(@error, 0, 0)
Case $Ret[0] = 0
Return SetError(4, _WinAPI_GetLastError(), 0)
Case Else
Return 1
EndSelect
EndFunc;==>_WinAPI_SetLayeredWindowAttributes
Edited by Michel Claveau
Link to comment
Share on other sites

Big thanks to ProgAndy for tidying this up for me.

I've just posted an update in the first post. I've changed to calculate the numeral positions and make the clock size configurable. It's not perfect but I'm sure someone else could take it from here :)

WBD

Link to comment
Share on other sites

Hi

I'm guessing I'm not using the latest build or inclusion. Why is this not recognized

_GDIPlus_GraphicsFillPolygon

_GDIPlus_GraphicsFillPolygon() was added in version 3.3.0.0
Link to comment
Share on other sites

copy this to the bottom of your current GDIPlus.au3

CODE
; #FUNCTION# ===================================================================================

; Name...........: _GDIPlus_GraphicsFillPolygon

; Description ...: Fill a polygon

; Syntax.........: _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints[, $hBrush = 0])

; Parameters ....: $hGraphics - Handle to a Graphics object

; $aPoints - Array that specify the vertices of the polygon:

; |[0][0] - Number of vertices

; |[1][0] - Vertice 1 X position

; |[1][1] - Vertice 1 Y position

; |[2][0] - Vertice 2 X position

; |[2][1] - Vertice 2 Y position

; |[n][0] - Vertice n X position

; |[n][1] - Vertice n Y position

; $hBrush - Handle to a brush object that is used to fill the polygon.

; - If $hBrush is 0, a solid black brush is used.

; Return values .: Success - True

; Failure - False

; Author ........:

; Modified.......: smashly

; Remarks .......:

; Related .......:

; Link ..........; @@MsdnLink@@ GdipFillPolygonI

; Example .......; Yes

; ===============================================================================================

Func _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush = 0)

Local $iI, $iCount, $pPoints, $tPoints, $aResult, $tmpError, $tmpExError

$iCount = $aPoints[0][0]

$tPoints = DllStructCreate("int[" & $iCount * 2 & "]")

$pPoints = DllStructGetPtr($tPoints)

For $iI = 1 To $iCount

DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)

DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)

Next

_GDIPlus_BrushDefCreate($hBrush)

$aResult = DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "hWnd", $hGraphics, "hWnd", $hBrush, _

"ptr", $pPoints, "int", $iCount, "int", "FillModeAlternate")

$tmpError = @error

$tmpExError = @extended

_GDIPlus_BrushDefDispose()

If $tmpError Then Return SetError($tmpError, $tmpExError, False)

Return SetError($aResult[0], 0, $aResult[0] = 0)

EndFunc ;==>_GDIPlus_GraphicsFillPolygon

Link to comment
Share on other sites

Hi

Added some things to it:

1) Memory reduction function

2) Left click anywhere and drag

3) Used the _Gui_round_corners function to remove white space. Clock now "floats"

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $clockSize=240
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()
_ReduceMemory()
_GuiRoundCorners($hWnd, 24, 43, 200, 200)

Do
    _WinMove("Clock")
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

Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
   Dim $pos, $ret, $ret2
   $pos = WinGetPos($h_win)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long",  $i_x1, "long", $i_y1, "long", $pos[2]-22, "long", $pos[3]-22, "long", $i_x3,  "long", $i_y3)
   If $ret[0] Then
      $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
      If $ret2[0] Then
         Return 1
      Else
         Return 0
      EndIf
   Else
      Return 0
   EndIf
EndFunc;==>_GuiRoundCorners

;===============================================================================
;
; Description:    Moves any Window by Left Mouse "Click & Drag"
; Syntax:          _WinMove($hWnd) or  _WinMove($s_Title)
; Parameter(s):  $s_hWnd = as returned by GUICreate()
;                  $s_Title = title of window to be moved
; Requirement(s):   None
; Return Value(s):  On Success - Repositions the Window
;                  On Failure - Returns ""
; Author(s):        Valuater,  Valuater [at] aol [.com], Inspired by Martin
;
;===============================================================================
Func _WinMove($hWnd)
    If Not WinActive($hWnd) Then Return
    Local $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
    If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
    Local $a = WinGetPos($hWnd), $b = MouseGetPos()
    If $b[0] < $a[0] Or $b[1] < $a[1] Or $b[0] > $a[2] + $a[0] Or $b[1] > $a[3] + $a[1] Then Return
    While WinActive($hWnd)
        Local $c = MouseGetPos()
        WinMove($hWnd, '', $a[0] + $c[0] - $b[0], $a[1] + $c[1] - $b[1])
        $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
        If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
    WEnd
EndFunc  ;==>_WinMove

; Reduce memory usage
; Author wOuter ( mostly )

Func _ReduceMemory($i_PID = -1)
    
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
    
    Return $ai_Return[0]
EndFunc;==> _ReduceMemory()
Link to comment
Share on other sites

Hi!

New modified version.

With the _winmove of Picea892, and others modifs from ProgAndy.

Accept two parameters (X & Y) ; right align by default or by -1.

And, allways, invisible background & popup mode (without border).

Re. Another little thing: I modified the write of hours (1 to 12).

And I added date.

#NoTrayIcon
#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\ponx.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=http://mclaveau.com
#AutoIt3Wrapper_Res_Fileversion=0.2
#AutoIt3Wrapper_Res_LegalCopyright=Michel Claveau Informatique
#AutoIt3Wrapper_Res_Language=1036
#AutoIt3Wrapper_Res_Field=CompanyName|Michel Claveau Informatique
#AutoIt3Wrapper_Res_Field=ProductVersion|0.2
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
; credits to WideBoyDixon
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#Include <Date.au3>

Opt("GUIOnEventMode", 1)
$width = 200
$height = 200

$xx=-1
$yy=-1
if $CmdLine[0]>0 then
$xx=$CmdLine[1]
EndIf
if $CmdLine[0]>1 then
$yy=$CmdLine[2]
EndIf
If $xx<0 Then $xx=@DesktopWidth-$width+30
If $yy<0 Then $yy=0

Dim $mois[13]=[' ','Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre']
;Dim $mois[13]=[' ','Janvier','Février','Mars','Avril','Décembre','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre']


$hWnd = GUICreate("Clock", $width-30, $height-30, $xx,$yy)
GUISetBkColor(0xFF88FF)
GUISetStyle($WS_POPUP,$WS_EX_LAYERED, $hWnd)
_WinAPI_SetLayeredWindowAttributes($hWnd, 0xFF88FF)

GUISetOnEvent($GUI_EVENT_CLOSE, "close")

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)

$inc = 0
AdlibEnable("_DrawClock",200)
$lgBrush = _GDIPlus_CreateLineBrushFromRect(0, 0, $width, $height, -1, -1, 0xFF7878FF, 0xFF000000, 0)
$irBrush = _GDIPlus_CreateLineBrushFromRect(0, 0, $width, $height, -1, -1, 0xFF000000, 0xFF7878FF, 0)
$nuBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF22)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$nuFont = _GDIPlus_FontCreate($hFamily, 12, 1)
$nuFont2 = _GDIPlus_FontCreate($hFamily, 8, 1)

$hourBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$minuteBrush = _GDIPlus_BrushCreateSolid(0xFFD0D0D0)
$secondPen = _GDIPlus_PenCreate(0xFFFF0000, 1)

$bitmap2 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer2 = _GDIPlus_ImageGetGraphicsContext($bitmap2)

_GDIPlus_GraphicsSetSmoothingMode($backbuffer2, 4)
;_GDIPlus_GraphicsClear($backbuffer2, 0xFFFFFFFF)

; _GDIPlus_GraphicsFillEllipse($backbuffer2, 25, 25, $width-30, $height-30, $lgBrush)
; _GDIPlus_GraphicsFillEllipse($backbuffer2, 35, 35, $width-30-20, $height-30-20, $irBrush)
; _GDIPlus_GraphicsFillEllipse($backbuffer2, 38, 38, $width-30-20-6, $height-30-20-6, $lgBrush)

_GDIPlus_GraphicsFillEllipse($backbuffer2, 0, 0, $width-30, $height-30, $lgBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer2, 10, 10, $width-30-20, $height-30-20, $irBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer2, 13, 13, $width-30-20-6, $height-30-20-6, $lgBrush)


$pi = 3.14159265358979
$degToRad = $pi / 180
$coeff=int(($width)/3)-4
For $i=12 to 1 step -1
$j=360/12*$i-90
If $j>=360 Then $j-=360
$x=int(Cos($j*$degToRad)*$coeff+$coeff)+16
$y=int(Sin($j*$degToRad)*$coeff+$coeff)+16
If $i>9 Then $x-=2
_DrawMyText($i, $x,$y)
Next


$tmp=@MDAY &" "& $mois[int(@MON)]
$xdat=12-StringLen($tmp)
$xdat=$xdat*4

_DrawMyTextPetit($tmp,int($width*0.3)-16+$xdat,int($height*0.52))

GUIRegisterMsg($WM_PAINT,"MY_PAINT")
GUISetState()
Do
_WinMove("Clock")
Until Not Sleep(249)


Func MY_PAINT($hWnd,$uMsg,$lParam,$wParam)
_DrawClock()
Return $GUI_RUNDEFMSG
EndFunc


Func _DrawClock()
$diametre=100-15
$rayon=$diametre/2
_GDIPlus_GraphicsDrawImage($backbuffer,$bitmap2,0,0)
;Create angles
$secondAngle = 8.0 * ATan(1) * @SEC / 60.0
$minuteAngle = 8.0 * ATan(1) * (@MIN + @SEC / 60.0) / 60.0
$hourAngle = 8.0 * ATan(1) * (@HOUR + @MIN / 60.0) / 12.0

;Draw Hour Hand
Local $HourArrow[5][2] = [[4, 0], _
[Int(40 * Sin($hourAngle)) + $diametre, Int(-40 * Cos($hourAngle)) + $diametre], _
[Int(-5 * Cos($hourAngle)) + $diametre, Int(-5 * Sin($hourAngle)) + $diametre], _
[Int(5 * Cos($hourAngle)) + $diametre, Int(5 * Sin($hourAngle)) + $diametre], _
[Int(40 * Sin($hourAngle)) + $diametre, Int(-40 * Cos($hourAngle)) + $diametre]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $HourArrow, $hourBrush)
;~ _GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $hourBrush)

Local $MinuteArrow[5][2] = [[4, 0], _
[Int(70 * Sin($minuteAngle)) + $diametre, Int(-70 * Cos($minuteAngle)) + $diametre], _
[Int(-5 * Cos($minuteAngle)) + $diametre, Int(-5 * Sin($minuteAngle)) + $diametre], _
[Int(5 * Cos($minuteAngle)) + $diametre, Int(5 * Sin($minuteAngle)) + $diametre], _
[Int(70 * Sin($minuteAngle)) + $diametre, Int(-70 * Cos($minuteAngle)) + $diametre]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $MinuteArrow, $minuteBrush)
;;;_GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $minuteBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer, $width/2-20, $width/2-20, 10, 10, $minuteBrush)

_GDIPlus_GraphicsDrawLine($backbuffer, $diametre, $diametre, Int(70 * Sin($secondAngle)) + $diametre, _
Int(-70 * Cos($secondAngle)) + $diametre, $secondPen)

_GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0)
EndFunc


Func _DrawMyText($text, $x, $y)
$tLayout = _GDIPlus_RectFCreate($x, $y)
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont, $aInfo[0], $hFormat, $nuBrush)
EndFunc;==>_DrawMyText

Func _DrawMyTextPetit($text, $x, $y)
$tLayout = _GDIPlus_RectFCreate($x, $y)
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont2, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont2, $aInfo[0], $hFormat, $nuBrush)
EndFunc;==>_DrawMyText

Func close()
_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;==>close

;==== 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: [url="http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx"]http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx[/url]
;
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

$hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
"ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
Return $aRet[6]; Handle of Line Brush
EndFunc;==>_GDIPlus_CreateLineBrushFromRect




Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
If Not $isColorRef Then
$i_transcolor = Hex(String($i_transcolor), 6)
$i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
EndIf
Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
Select
Case @error
Return SetError(@error, 0, 0)
Case $Ret[0] = 0
Return SetError(4, _WinAPI_GetLastError(), 0)
Case Else
Return 1
EndSelect
EndFunc;==>_WinAPI_SetLayeredWindowAttributes


;===============================================================================
;
; Description: Moves any Window by Left Mouse "Click & Drag"
; Syntax: _WinMove($hWnd) or _WinMove($s_Title)
; Parameter(s): $s_hWnd = as returned by GUICreate()
; $s_Title = title of window to be moved
; Requirement(s): None
; Return Value(s): On Success - Repositions the Window
; On Failure - Returns ""
; Author(s): Valuater, Valuater [at] aol [.com], Inspired by Martin
;
;===============================================================================
Func _WinMove($hWnd)
If Not WinActive($hWnd) Then Return
Local $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
Local $a = WinGetPos($hWnd), $b = MouseGetPos()
If $b[0] < $a[0] Or $b[1] < $a[1] Or $b[0] > $a[2] + $a[0] Or $b[1] > $a[3] + $a[1] Then Return
While WinActive($hWnd)
Local $c = MouseGetPos()
WinMove($hWnd, '', $a[0] + $c[0] - $b[0], $a[1] + $c[1] - $b[1])
$a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
WEnd
EndFunc;==>_WinMove
Edited by Michel Claveau
Link to comment
Share on other sites

Nice work Michel! Much as I love all our cousins across la manche, I'm not keen on using French month names on my clock. I changed this to #include my GetLocaleInfo script:

#include-once

Global Const $LOCALE_NOUSEROVERRIDE         = 0x80000000   ;// do not use user overrides
Global Const $LOCALE_USE_CP_ACP             = 0x40000000   ;// use the system ACP
Global Const $LOCALE_RETURN_NUMBER          = 0x20000000   ;// return number instead of string

;//
;//  The following LCTypes are mutually exclusive in that they may NOT
;//  be used in combination with each other.
;//
Global Const $LOCALE_ILANGUAGE              = 0x00000001   ;// language id
Global Const $LOCALE_SLANGUAGE              = 0x00000002   ;// localized name of language
Global Const $LOCALE_SENGLANGUAGE           = 0x00001001   ;// English name of language
Global Const $LOCALE_SABBREVLANGNAME        = 0x00000003   ;// abbreviated language name
Global Const $LOCALE_SNATIVELANGNAME        = 0x00000004   ;// native name of language

Global Const $LOCALE_ICOUNTRY               = 0x00000005   ;// country code
Global Const $LOCALE_SCOUNTRY               = 0x00000006   ;// localized name of country
Global Const $LOCALE_SENGCOUNTRY            = 0x00001002   ;// English name of country
Global Const $LOCALE_SABBREVCTRYNAME        = 0x00000007   ;// abbreviated country name
Global Const $LOCALE_SNATIVECTRYNAME        = 0x00000008   ;// native name of country

Global Const $LOCALE_IDEFAULTLANGUAGE       = 0x00000009   ;// default language id
Global Const $LOCALE_IDEFAULTCOUNTRY        = 0x0000000A   ;// default country code
Global Const $LOCALE_IDEFAULTCODEPAGE       = 0x0000000B   ;// default oem code page
Global Const $LOCALE_IDEFAULTANSICODEPAGE   = 0x00001004   ;// default ansi code page
Global Const $LOCALE_IDEFAULTMACCODEPAGE    = 0x00001011   ;// default mac code page

Global Const $LOCALE_SLIST                  = 0x0000000C   ;// list item separator
Global Const $LOCALE_IMEASURE               = 0x0000000D   ;// 0 = metric, 1 = US

Global Const $LOCALE_SDECIMAL               = 0x0000000E   ;// decimal separator
Global Const $LOCALE_STHOUSAND              = 0x0000000F   ;// thousand separator
Global Const $LOCALE_SGROUPING              = 0x00000010   ;// digit grouping
Global Const $LOCALE_IDIGITS                = 0x00000011   ;// number of fractional digits
Global Const $LOCALE_ILZERO                 = 0x00000012   ;// leading zeros for decimal
Global Const $LOCALE_INEGNUMBER             = 0x00001010   ;// negative number mode
Global Const $LOCALE_SNATIVEDIGITS          = 0x00000013   ;// native ascii 0-9

Global Const $LOCALE_SCURRENCY              = 0x00000014   ;// local monetary symbol
Global Const $LOCALE_SINTLSYMBOL            = 0x00000015   ;// intl monetary symbol
Global Const $LOCALE_SMONDECIMALSEP         = 0x00000016   ;// monetary decimal separator
Global Const $LOCALE_SMONTHOUSANDSEP        = 0x00000017   ;// monetary thousand separator
Global Const $LOCALE_SMONGROUPING           = 0x00000018   ;// monetary grouping
Global Const $LOCALE_ICURRDIGITS            = 0x00000019   ;// # local monetary digits
Global Const $LOCALE_IINTLCURRDIGITS        = 0x0000001A   ;// # intl monetary digits
Global Const $LOCALE_ICURRENCY              = 0x0000001B   ;// positive currency mode
Global Const $LOCALE_INEGCURR               = 0x0000001C   ;// negative currency mode

Global Const $LOCALE_SDATE                  = 0x0000001D   ;// date separator
Global Const $LOCALE_STIME                  = 0x0000001E   ;// time separator
Global Const $LOCALE_SSHORTDATE             = 0x0000001F   ;// short date format string
Global Const $LOCALE_SLONGDATE              = 0x00000020   ;// long date format string
Global Const $LOCALE_STIMEFORMAT            = 0x00001003   ;// time format string
Global Const $LOCALE_IDATE                  = 0x00000021   ;// short date format ordering
Global Const $LOCALE_ILDATE                 = 0x00000022   ;// long date format ordering
Global Const $LOCALE_ITIME                  = 0x00000023   ;// time format specifier
Global Const $LOCALE_ITIMEMARKPOSN          = 0x00001005   ;// time marker position
Global Const $LOCALE_ICENTURY               = 0x00000024   ;// century format specifier (short date)
Global Const $LOCALE_ITLZERO                = 0x00000025   ;// leading zeros in time field
Global Const $LOCALE_IDAYLZERO              = 0x00000026   ;// leading zeros in day field (short date)
Global Const $LOCALE_IMONLZERO              = 0x00000027   ;// leading zeros in month field (short date)
Global Const $LOCALE_S1159                  = 0x00000028   ;// AM designator
Global Const $LOCALE_S2359                  = 0x00000029   ;// PM designator

Global Const $LOCALE_ICALENDARTYPE          = 0x00001009   ;// type of calendar specifier
Global Const $LOCALE_IOPTIONALCALENDAR      = 0x0000100B   ;// additional calendar types specifier
Global Const $LOCALE_IFIRSTDAYOFWEEK        = 0x0000100C   ;// first day of week specifier
Global Const $LOCALE_IFIRSTWEEKOFYEAR       = 0x0000100D   ;// first week of year specifier

Global Const $LOCALE_SDAYNAME1              = 0x0000002A   ;// long name for Monday
Global Const $LOCALE_SDAYNAME2              = 0x0000002B   ;// long name for Tuesday
Global Const $LOCALE_SDAYNAME3              = 0x0000002C   ;// long name for Wednesday
Global Const $LOCALE_SDAYNAME4              = 0x0000002D   ;// long name for Thursday
Global Const $LOCALE_SDAYNAME5              = 0x0000002E   ;// long name for Friday
Global Const $LOCALE_SDAYNAME6              = 0x0000002F   ;// long name for Saturday
Global Const $LOCALE_SDAYNAME7              = 0x00000030   ;// long name for Sunday
Global Const $LOCALE_SABBREVDAYNAME1        = 0x00000031   ;// abbreviated name for Monday
Global Const $LOCALE_SABBREVDAYNAME2        = 0x00000032   ;// abbreviated name for Tuesday
Global Const $LOCALE_SABBREVDAYNAME3        = 0x00000033   ;// abbreviated name for Wednesday
Global Const $LOCALE_SABBREVDAYNAME4        = 0x00000034   ;// abbreviated name for Thursday
Global Const $LOCALE_SABBREVDAYNAME5        = 0x00000035   ;// abbreviated name for Friday
Global Const $LOCALE_SABBREVDAYNAME6        = 0x00000036   ;// abbreviated name for Saturday
Global Const $LOCALE_SABBREVDAYNAME7        = 0x00000037   ;// abbreviated name for Sunday
Global Const $LOCALE_SMONTHNAME1            = 0x00000038   ;// long name for January
Global Const $LOCALE_SMONTHNAME2            = 0x00000039   ;// long name for February
Global Const $LOCALE_SMONTHNAME3            = 0x0000003A   ;// long name for March
Global Const $LOCALE_SMONTHNAME4            = 0x0000003B   ;// long name for April
Global Const $LOCALE_SMONTHNAME5            = 0x0000003C   ;// long name for May
Global Const $LOCALE_SMONTHNAME6            = 0x0000003D   ;// long name for June
Global Const $LOCALE_SMONTHNAME7            = 0x0000003E   ;// long name for July
Global Const $LOCALE_SMONTHNAME8            = 0x0000003F   ;// long name for August
Global Const $LOCALE_SMONTHNAME9            = 0x00000040   ;// long name for September
Global Const $LOCALE_SMONTHNAME10           = 0x00000041   ;// long name for October
Global Const $LOCALE_SMONTHNAME11           = 0x00000042   ;// long name for November
Global Const $LOCALE_SMONTHNAME12           = 0x00000043   ;// long name for December
Global Const $LOCALE_SMONTHNAME13           = 0x0000100E   ;// long name for 13th month (if exists)
Global Const $LOCALE_SABBREVMONTHNAME1      = 0x00000044   ;// abbreviated name for January
Global Const $LOCALE_SABBREVMONTHNAME2      = 0x00000045   ;// abbreviated name for February
Global Const $LOCALE_SABBREVMONTHNAME3      = 0x00000046   ;// abbreviated name for March
Global Const $LOCALE_SABBREVMONTHNAME4      = 0x00000047   ;// abbreviated name for April
Global Const $LOCALE_SABBREVMONTHNAME5      = 0x00000048   ;// abbreviated name for May
Global Const $LOCALE_SABBREVMONTHNAME6      = 0x00000049   ;// abbreviated name for June
Global Const $LOCALE_SABBREVMONTHNAME7      = 0x0000004A   ;// abbreviated name for July
Global Const $LOCALE_SABBREVMONTHNAME8      = 0x0000004B   ;// abbreviated name for August
Global Const $LOCALE_SABBREVMONTHNAME9      = 0x0000004C   ;// abbreviated name for September
Global Const $LOCALE_SABBREVMONTHNAME10     = 0x0000004D   ;// abbreviated name for October
Global Const $LOCALE_SABBREVMONTHNAME11     = 0x0000004E   ;// abbreviated name for November
Global Const $LOCALE_SABBREVMONTHNAME12     = 0x0000004F   ;// abbreviated name for December
Global Const $LOCALE_SABBREVMONTHNAME13     = 0x0000100F   ;// abbreviated name for 13th month (if exists)

Global Const $LOCALE_SPOSITIVESIGN          = 0x00000050   ;// positive sign
Global Const $LOCALE_SNEGATIVESIGN          = 0x00000051   ;// negative sign
Global Const $LOCALE_IPOSSIGNPOSN           = 0x00000052   ;// positive sign position
Global Const $LOCALE_INEGSIGNPOSN           = 0x00000053   ;// negative sign position
Global Const $LOCALE_IPOSSYMPRECEDES        = 0x00000054   ;// mon sym precedes pos amt
Global Const $LOCALE_IPOSSEPBYSPACE         = 0x00000055   ;// mon sym sep by space from pos amt
Global Const $LOCALE_INEGSYMPRECEDES        = 0x00000056   ;// mon sym precedes neg amt
Global Const $LOCALE_INEGSEPBYSPACE         = 0x00000057   ;// mon sym sep by space from neg amt

Global Const $LOCALE_FONTSIGNATURE          = 0x00000058   ;// font signature
Global Const $LOCALE_SISO639LANGNAME        = 0x00000059   ;// ISO abbreviated language name
Global Const $LOCALE_SISO3166CTRYNAME       = 0x0000005A   ;// ISO abbreviated country name

Global Const $LOCALE_IDEFAULTEBCDICCODEPAGE = 0x00001012   ;// default ebcdic code page
Global Const $LOCALE_IPAPERSIZE             = 0x0000100A   ;// 0 = letter, 1 = a4, 2 = legal, 3 = a3
Global Const $LOCALE_SENGCURRNAME           = 0x00001007   ;// english name of currency
Global Const $LOCALE_SNATIVECURRNAME        = 0x00001008   ;// native name of currency
Global Const $LOCALE_SYEARMONTH             = 0x00001006   ;// year month format string
Global Const $LOCALE_SSORTNAME              = 0x00001013   ;// sort name
Global Const $LOCALE_IDIGITSUBSTITUTION     = 0x00001014   ;// 0 = none, 1 = context, 2 = native digit

Func _WinAPI_GetLocaleInfo($Locale, $LCType)
    Local $aResult = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", $Locale, "long", $LCType, "ptr", 0, "long", 0)
    If @error Then Return SetError(1, 0, "")
    Local $lpBuffer = DllStructCreate("char[" & $aResult[0] & "]")
    $aResult = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", $Locale, "long", $LCType, "ptr", DllStructGetPtr($lpBuffer), "long", $aResult[0])
    If @error Or ($aResult[0] = 0) Then Return SetError(1, 0, "")
    Return SetError(0, 0, DllStructGetData($lpBuffer, 1))
EndFunc

Func _WinAPI_GetUserDefaultLCID()
    Local $aResult = DllCall("kernel32.dll", "long", "GetUserDefaultLCID") ; Get the default LCID for this user
    If @error Then Return SetError(1, 0, 0)
    Return SetError(0, 0, $aResult[0])
EndFuncƒoÝŠ÷ Ø‹azzÞš‹ÞvØ^uçâž+b¢zÓ~¦¢+×!jxvØb²X§y«­¢+ؘŒÀÌØíѵÀõ5d€™…µÀì™ÅÕ½Ð쀙ÅÕ½Ðì™…µÀ쀘ŒÀÌØíµ½¥Ím¥¹Ð¡5=8¥tƒoÝŠ÷ Ù:-+ºÚ"µÍ‰ˆÌÍŽÝHQVH  ˜[È   œ][ÝÈ    œ][ÝÈ    ˜[ÈÕÚ[TWÑÙ]ØØ[R[™›ÊÕÚ[TWÑÙ]Ù‘Y˜][ÒQ

K   ˆÌÍŽÓÐÐSWÔÓSÓ•SQLH
ÈSÓˆHJ

That means I get the right month names from the OS. You could replace $LOCALE_SMONTHNAME1 with $LOCALE_SABBREVMONTHNAME1 in order to get the abbreviated month name.

I might still be looking to polish this up a little to go in my collection; I hope nobody minds if I take in their individual amendments in to a community-developed clock :) I'm all for development by community :party:

WBD

Edited by WideBoyDixon
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...