#NoTrayIcon
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Opt("GUIOnEventMode", 1)

$iWidth = 115
$iHeight = 50
$iX_Pos = @DesktopWidth / 2 - 56
$iY_Pos = @DesktopHeight / 2 - 25

#region -DLLStruct
$tPoint = DllStructCreate($tagPOINT)
DllStructSetData($tPoint, "X", 0)
DllStructSetData($tPoint, "Y", 0)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", $iWidth)
DllStructSetData($tSize, "Y", $iHeight)
$tDest = DllStructCreate($tagPOINT)
$pDest = DllStructGetPtr($tDest)
DllStructSetData($tDest, "X", $iX_Pos)
DllStructSetData($tDest, "Y", $iY_Pos)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", 255)
DllStructSetData($tBlend, "Format", 1)
#endregion -DLLStruct

$hWnd = GUICreate("Clock", $iWidth, $iHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
GUISetState()

$hDC_Window = _WinAPI_GetDC($hWnd)
$hDC_Bitmap = _WinAPI_CreateCompatibleDC($hDC_Window)
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iWidth, $iHeight)
_WinAPI_SelectObject($hDC_Bitmap, $hBitmap)

_GDIPlus_Startup()

$hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Bitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
_GDIPlus_GraphicsSetTextRenderingHint($hGraphics, 3)

$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Sony Sketch EF")
$hFont = _GDIPlus_FontCreate($hFamily, 20)

$tLayout_HourX10 = _GDIPlus_RectFCreate(0)
$tLayout_HourX1 = _GDIPlus_RectFCreate(16)
$tLayout_Colon1 = _GDIPlus_RectFCreate(34, $iHeight / 2 - 15)
$tLayout_MinX10 = _GDIPlus_RectFCreate(40)
$tLayout_MinX1 = _GDIPlus_RectFCreate(56)
$tLayout_Colon2 = _GDIPlus_RectFCreate(74, $iHeight / 2 - 15)
$tLayout_SecX10 = _GDIPlus_RectFCreate(80)
$tLayout_SecX1 = _GDIPlus_RectFCreate(96)

$hBrush_Numbers = _GetBrush()

OnAutoItExitRegister("_Shutdown")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $hWnd)

While Sleep(30)
	_GDIPlus_GraphicsClear($hGraphics, 0)

	$iSecX1 = Mod(@SEC, 10)
	$iSecX10 = Floor(@SEC / 10)
	$iMinX1 = Mod(@MIN, 10)
	$iMinX10 = Floor(@MIN / 10)
	$iHourX1 = Mod(@HOUR, 10)
	$iHourX10 = Floor(@HOUR / 10)

	$iY_SecX1 = @MSEC / 1000 * $iHeight / 3 - 9
	If $iSecX1 = 0 Then
		$iY_SecX10 = $iY_SecX1
	Else
		$iY_SecX10 = $iHeight / 3 - 9
	EndIf
	If @SEC = 0 Then
		$iY_MinX1 = $iY_SecX1
	Else
		$iY_MinX1 = $iHeight / 3 - 9
	EndIf
	If $iMinX1 = 0 And @SEC = 0 Then
		$iY_MinX10 = $iY_SecX1
	Else
		$iY_MinX10 = $iHeight / 3 - 9
	EndIf
	If @MIN = 0 And @SEC = 0 Then
		$iY_HourX1 = $iY_SecX1
	Else
		$iY_HourX1 = $iHeight / 3 - 9
	EndIf
	If $iHourX1 = 0 And @MIN = 0 And @SEC = 0 Then
		$iY_HourX10 = $iY_SecX1
	Else
		$iY_HourX10 = $iHeight / 3 - 9
	EndIf

	#region -Hours
	DllStructSetData($tLayout_HourX1, "Y", $iHeight - $iY_HourX1 - 15)
	If ($iHourX1 = 3 And $iHourX10 = 2) Or $iHourX1 = 9 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 0, $hFont, $tLayout_HourX1, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iHourX1 + 1, $hFont, $tLayout_HourX1, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_HourX1, "Y", $iHeight / 3 * 2 - $iY_HourX1 - 15)
	_GDIPlus_GraphicsDrawStringEx($hGraphics, $iHourX1, $hFont, $tLayout_HourX1, $hFormat, $hBrush_Numbers)

	DllStructSetData($tLayout_HourX1, "Y", $iHeight / 3 - $iY_HourX1 - 15)
	If $iHourX1 = 0 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 9, $hFont, $tLayout_HourX1, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iHourX1 - 1, $hFont, $tLayout_HourX1, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_HourX10, "Y", $iHeight - $iY_HourX10 - 15)
	If $iHourX10 = 2 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 0, $hFont, $tLayout_HourX10, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iHourX10 + 1, $hFont, $tLayout_HourX10, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_HourX10, "Y", $iHeight / 3 * 2 - $iY_HourX10 - 15)
	_GDIPlus_GraphicsDrawStringEx($hGraphics, $iHourX10, $hFont, $tLayout_HourX10, $hFormat, $hBrush_Numbers)

	DllStructSetData($tLayout_HourX10, "Y", $iHeight / 3 - $iY_HourX10 - 15)
	If $iHourX10 = 0 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 2, $hFont, $tLayout_HourX10, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iHourX10 - 1, $hFont, $tLayout_HourX10, $hFormat, $hBrush_Numbers)
	EndIf
	#endregion -Hours

	#region -Minutes
	DllStructSetData($tLayout_MinX1, "Y", $iHeight - $iY_MinX1 - 15)
	If $iMinX1 = 9 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 0, $hFont, $tLayout_MinX1, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iMinX1 + 1, $hFont, $tLayout_MinX1, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_MinX1, "Y", $iHeight / 3 * 2 - $iY_MinX1 - 15)
	_GDIPlus_GraphicsDrawStringEx($hGraphics, $iMinX1, $hFont, $tLayout_MinX1, $hFormat, $hBrush_Numbers)

	DllStructSetData($tLayout_MinX1, "Y", $iHeight / 3 - $iY_MinX1 - 15)
	If $iMinX1 = 0 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 9, $hFont, $tLayout_MinX1, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iMinX1 - 1, $hFont, $tLayout_MinX1, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_MinX10, "Y", $iHeight - $iY_MinX10 - 15)
	If $iMinX10 = 5 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 0, $hFont, $tLayout_MinX10, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iMinX10 + 1, $hFont, $tLayout_MinX10, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_MinX10, "Y", $iHeight / 3 * 2 - $iY_MinX10 - 15)
	_GDIPlus_GraphicsDrawStringEx($hGraphics, $iMinX10, $hFont, $tLayout_MinX10, $hFormat, $hBrush_Numbers)

	DllStructSetData($tLayout_MinX10, "Y", $iHeight / 3 - $iY_MinX10 - 15)
	If $iMinX10 = 0 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 5, $hFont, $tLayout_MinX10, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iMinX10 - 1, $hFont, $tLayout_MinX10, $hFormat, $hBrush_Numbers)
	EndIf
	#endregion -Minutes

	#region -Seconds
	DllStructSetData($tLayout_SecX1, "Y", $iHeight - $iY_SecX1 - 15)
	If $iSecX1 = 9 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 0, $hFont, $tLayout_SecX1, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iSecX1 + 1, $hFont, $tLayout_SecX1, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_SecX1, "Y", $iHeight / 3 * 2 - $iY_SecX1 - 15)
	_GDIPlus_GraphicsDrawStringEx($hGraphics, $iSecX1, $hFont, $tLayout_SecX1, $hFormat, $hBrush_Numbers)

	DllStructSetData($tLayout_SecX1, "Y", $iHeight / 3 - $iY_SecX1 - 15)
	If $iSecX1 = 0 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 9, $hFont, $tLayout_SecX1, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iSecX1 - 1, $hFont, $tLayout_SecX1, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_SecX10, "Y", $iHeight - $iY_SecX10 - 15)
	If $iSecX10 = 5 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 0, $hFont, $tLayout_SecX10, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iSecX10 + 1, $hFont, $tLayout_SecX10, $hFormat, $hBrush_Numbers)
	EndIf

	DllStructSetData($tLayout_SecX10, "Y", $iHeight / 3 * 2 - $iY_SecX10 - 15)
	_GDIPlus_GraphicsDrawStringEx($hGraphics, $iSecX10, $hFont, $tLayout_SecX10, $hFormat, $hBrush_Numbers)

	DllStructSetData($tLayout_SecX10, "Y", $iHeight / 3 - $iY_SecX10 - 15)
	If $iSecX10 = 0 Then
		_GDIPlus_GraphicsDrawStringEx($hGraphics, 5, $hFont, $tLayout_SecX10, $hFormat, $hBrush_Numbers)
	Else
		_GDIPlus_GraphicsDrawStringEx($hGraphics, $iSecX10 - 1, $hFont, $tLayout_SecX10, $hFormat, $hBrush_Numbers)
	EndIf
	#endregion -Seconds


	_GDIPlus_GraphicsDrawStringEx($hGraphics, ":", $hFont, $tLayout_Colon1, $hFormat, $hBrush_Numbers)
	_GDIPlus_GraphicsDrawStringEx($hGraphics, ":", $hFont, $tLayout_Colon2, $hFormat, $hBrush_Numbers)

	_WinAPI_UpdateLayeredWindow($hWnd, $hDC_Window, $pDest, $pSize, $hDC_Bitmap, $pSource, 0, $pBlend, $ULW_ALPHA)
WEnd

Func _GetBrush()
	$hBitmapTmp = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
	$hGraphicsTmp = _GDIPlus_ImageGetGraphicsContext($hBitmapTmp)
	$hBrushTmp1 = _GDIPlus_LineBrushCreate(0, $iHeight / 2 - 17, 0, $iHeight / 2, 0, 0xD0A0A0A0)
	$hBrushTmp2 = _GDIPlus_LineBrushCreate(0, $iHeight / 2, 0, $iHeight / 2 + 17, 0xD0A0A0A0, 0)

	_GDIPlus_GraphicsFillRect($hGraphicsTmp, 0, $iHeight / 2 - 17, $iWidth, 17, $hBrushTmp1)
	_GDIPlus_GraphicsFillRect($hGraphicsTmp, 0, $iHeight / 2, $iWidth, 17, $hBrushTmp2)
	$hReturn = _GDIPlus_TextureCreate($hBitmapTmp, 4)

	_GDIPlus_GraphicsDispose($hGraphicsTmp)
	_GDIPlus_BitmapDispose($hBitmapTmp)
	_GDIPlus_BrushDispose($hBrushTmp1)
	_GDIPlus_BrushDispose($hBrushTmp2)

	Return $hReturn
EndFunc

Func _Exit()
	Exit
EndFunc   ;==>_Exit

Func _Shutdown()
	_WinAPI_ReleaseDC($hWnd, $hDC_Window)
	_WinAPI_DeleteDC($hDC_Bitmap)
	_WinAPI_DeleteObject($hBitmap)

	_GDIPlus_GraphicsDispose($hGraphics)
	_GDIPlus_BrushDispose($hBrush_Numbers)
	_GDIPlus_StringFormatDispose($hFormat)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_FontDispose($hFont)
	_GDIPlus_Shutdown()
EndFunc   ;==>_Shutdown

#region GDIP Functions
Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)
	Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "hwnd", $hGraphics, "int", $iTextRenderingHint)

	If @error Then Return SetError(@error, @extended, False)
	$GDIP_STATUS = $aResult[0]
	Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetTextRenderingHint

Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0)
	Local $tPointF1, $pPointF1
	Local $tPointF2, $pPointF2
	Local $aResult

	$tPointF1 = DllStructCreate("float;float")
	$pPointF1 = DllStructGetPtr($tPointF1)
	$tPointF2 = DllStructCreate("float;float")
	$pPointF2 = DllStructGetPtr($tPointF2)

	DllStructSetData($tPointF1, 1, $nX1)
	DllStructSetData($tPointF1, 2, $nY1)
	DllStructSetData($tPointF2, 1, $nX2)
	DllStructSetData($tPointF2, 2, $nY2)

	$aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0)

	If @error Then Return SetError(@error, @extended, 0)
	$GDIP_STATUS = $aResult[0]
	Return $aResult[6]
EndFunc   ;==>_GDIPlus_LineBrushCreate

Func _GDIPlus_TextureCreate($hImage, $iWrapMode = 0)
	Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hImage, "int", $iWrapMode, "int*", 0)

	If @error Then Return SetError(@error, @extended, 0)
	$GDIP_STATUS = $aResult[0]
	Return $aResult[3]
EndFunc   ;==>_GDIPlus_TextureCreate
#endregion GDIP Functions