#Include <APIConstants.au3>
#Include <GDIPlus.au3>
#Include <Timers.au3>
#Include <WinAPIEx.au3>
Opt('TrayMenuMode', 1)
Global Const $hAutoIt = WinGetHandle(AutoItWinGetTitle())
Global $Count = @SEC
$Exit = TrayCreateItem('Exit')
_GDIPlus_Startup()
_Timer_SetTimer(0, 1000, '_Count')
_Count(0, 0, 0, 0)
Do
Until TrayGetMsg() = $Exit
_Timer_KillAllTimers(0)
_GDIPlus_Shutdown()
Func _Count($hWnd, $iMsg, $ID, $iTime)
#forceref $hWnd, $iMsg, $ID, $iTime
_SetTrayIcon(StringFormat('%02d', $Count), 0xA0C00000)
$Count += 1
If $Count > 59 Then
$Count = 0
EndIf
EndFunc ;==>_Count
Func _SetTrayIcon($sSeconds, $iColor = 0xFF000000)
Static $hPrev = 0
Local $tNID, $hBitmap[2], $hIcon, $hGraphic, $hImage, $hBrush, $hFormat, $hFamily, $hFont, $pBits, $aData, $tData
$hImage = _GDIPlus_CreateBitmapFromScan0(16, 16)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
$hBrush = _GDIPlus_BrushCreateSolid($iColor)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate('Impact')
$hFont = _GDIPlus_FontCreate($hFamily, 11)
$aData = _GDIPlus_GraphicsMeasureString($hGraphic, $sSeconds, $hFont, _GDIPlus_RectFCreate(0, 0, 0, 0), $hFormat)
DllStructSetData($aData[0], 1, -2)
;~ DllStructSetData($aData[0], 1, (16 - DllStructGetData($aData[0], 3)) / 2)
DllStructSetData($aData[0], 2, (16 - DllStructGetData($aData[0], 4)) / 2)
_GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 4)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sSeconds, $hFont, $aData[0], $hFormat, $hBrush)
$hBitmap[0] = _WinAPI_CreateBitmap(16, 16, 1, 32)
$tData = _GDIPlus_BitmapLockBits($hImage, 0, 0, 16, 16, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
_WinAPI_SetBitmapBits($hBitmap[0], 1024, DllStructGetData($tData, 'Scan0'))
_GDIPlus_BitmapUnlockBits($hBitmap, $tData)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
$hBitmap[1] = _WinAPI_CreateBitmap(16, 16)
$hIcon = _WinAPI_CreateIconIndirect($hBitmap[0], $hBitmap[1])
For $i = 0 To 1
_WinAPI_DeleteObject($hBitmap[$i])
Next
$tNID = DllStructCreate($tagNOTIFYICONDATA)
DllStructSetData($tNID, 'Size', DllStructGetSize($tNID))
DllStructSetData($tNID, 'hWnd', $hAutoIt)
DllStructSetData($tNID, 'Flags', $NIF_ICON)
DllStructSetData($tNID, 'ID', 1)
DllStructSetData($tNID, 'hIcon', $hIcon)
_WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNID)
If $hPrev Then
_WinAPI_DestroyIcon($hPrev)
EndIf
$hPrev = $hIcon
EndFunc ;==>_SetTrayIcon
Func _GDIPlus_CreateBitmapFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipCreateBitmapFromScan0', 'int', $iWidth, 'int', $iHeight, 'int', $iStride, 'int', $iPixelFormat, 'ptr', $pScan0, 'ptr*', 0)
If @error Then
Return SetError(1, 0, 0)
Else
If $Ret[0] Then
Return SetError(1, $Ret[0], 0)
EndIf
EndIf
Return $Ret[6]
EndFunc ;==>_GDIPlus_CreateBitmapFromScan0
Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $iTextRenderingHint)
Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipSetTextRenderingHint', 'ptr', $hGraphic, 'int', $iTextRenderingHint)
If @error Then
Return SetError(1, 0, 0)
Else
If $Ret[0] Then
Return SetError(1, $Ret[0], 0)
EndIf
EndIf
Return 1
EndFunc ;==>_GDIPlus_GraphicsSetTextRenderingHint