Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ButtonConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #Include <WinAPI.au3>
- #include <EditConstants.au3>
- #include <Timers.au3>
- #include <MsgBoxConstants.au3>
- #include <Date.au3>
- #Include <GDIPlus.au3>
- #include <MsgBoxConstants.au3>
- #include <Array.au3>
- ; 04/09/2018 - last time used?
- ; 5/04/2018
- ; 6/25/2018 - 7PM
- Global Const $SobrietyDate = "2018/06/25 19:00:00"
- Global $Pictures[0]
- If WinExists("Sobriety Counter", "") Then
- MsgBox($MB_ICONERROR, "Error", "Sober counter is already running.")
- Exit(1)
- EndIf
- FindPictures()
- Global $hGui, $hCounter, $hTitle, $hHelpBtn, $strLastCounter
- Opt("TrayIconHide", 1)
- $hGui = GUICreate("Sobriety Counter", 324, 56, @DesktopWidth - 323, 0, $WS_POPUP, $WS_EX_LAYERED, WinGetHandle("Program Manager"))
- GUISetBkColor(0xABCDEF)
- $hCounter = GUICtrlCreateInput("", 0, 24, 330, 28, $ES_READONLY)
- GUICtrlSetFont($hCounter, 12, 800, 0, "MS Sans Serif")
- $hTitle = GUICtrlCreateLabel("Sobriety Counter", 0, 0, 150, 24)
- GUICtrlSetFont($hTitle, 12, 800, 0, "MS Sans Serif")
- GUICtrlSetColor($hTitle, 0xFFFFFF)
- $hHelpBtn = GUICtrlCreateButton("HELP!", 130, 0, 57, 25)
- GUICtrlSetFont($hHelpBtn, 8, 800, 0, "MS Sans Serif")
- GUICtrlSetColor($hHelpBtn, 0xFF0000)
- _WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF, 255)
- GUISetState(@SW_SHOW)
- _Timer_SetTimer($hGui, 2000, "_TimerUpdateCounter")
- UpdateCounter()
- Local $ShowingPics = false, $picTimer
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $hHelpBtn
- If $ShowingPics = false Then
- $picTimer = _Timer_SetTimer($hGui, 5000, "_TimerFaces")
- UpdateFaces()
- $ShowingPics = True
- Else
- SplashOff()
- _Timer_KillTimer($hGui, $picTimer)
- $ShowingPics = False
- EndIf
- EndSwitch
- WEnd
- ;
- Func _TimerFaces($hWnd, $Msg, $iIDTimer, $dwTime)
- UpdateFaces()
- EndFunc ;==>_TimerFaces
- Func UpdateFaces()
- Local $strFilename = GetRandomPicture()
- Local $siz = ImageSize( $strFilename )
- if($siz[0] > (@DesktopWidth - 25)) OR($siz[1] > (@DesktopHeight - 25)) Then
- $siz[0] = $siz[0] / 1.4
- $siz[1] = $siz[1] / 1.4
- EndIf
- SplashImageOn("Is this what you want?", $strFilename, $siz[0], $siz[1])
- EndFunc ;==>UpdateFaces
- Func _TimerUpdateCounter($hWnd, $Msg, $iIDTimer, $dwTime)
- UpdateCounter()
- EndFunc ;==>_TimerUpdateCounter
- Func UpdateCounter()
- Local $Seconds = _DateDiff('s', $SobrietyDate, _NowCalc())
- Local $Days = 0, $Hours = 0, $Minutes = 0
- Local $Str, $i
- $i = Int($Seconds / 86400)
- If $i >= 1 Then
- $Seconds = $Seconds - (86400 * $i)
- $Days = $i
- EndIf
- $i = Int($Seconds / 3600)
- If $i >= 1 Then
- $Seconds = $Seconds - (3600 * $i)
- $Hours = $i
- EndIf
- $i = Int($Seconds / 60)
- If $i >= 1 Then
- $Seconds = $Seconds - (60 * $i)
- $Minutes = $i
- EndIf
- $Str = Plural($Days, "Day") & ", " & Plural($Hours, "Hour") & ", and " & Plural($Minutes, "Minute")
- If $strLastCounter <> $Str Then
- $strLastCounter = $Str
- GUICtrlSetData($hCounter, $Str)
- EndIf
- EndFunc ;==>UpdateCounter
- Func ImageSize($file)
- Local $t[2]
- _GDIPlus_Startup()
- Local $hImage = _GDIPlus_ImageLoadFromFile($file)
- If @error Then
- MsgBox(16, "Error", "Does the file exist? " & $file)
- Exit 1
- EndIf
- $t[0] = _GDIPlus_ImageGetWidth($hImage)
- $t[1] = _GDIPlus_ImageGetHeight($hImage)
- _GDIPlus_ImageDispose($hImage)
- _GDIPlus_ShutDown()
- Return $t
- EndFunc ;==>ImageSize
- Func GetRandomPicture()
- Local $rand = Random(0, UBound($Pictures)-1, 1 )
- Local $pic = $Pictures[$rand]
- Return $pic;
- EndFunc
- Func FindPictures()
- Local $hSearch = FileFindFirstFile(@ScriptDir & "\faces\*.jpg" )
- Local $sPictures[0], $sFileName = "", $iResult = 0
- If $hSearch = -1 Then
- Return False
- EndIf
- While 1
- $sFileName = FileFindNextFile($hSearch)
- If @error Then ExitLoop
- _ArrayAdd( $Pictures, @ScriptDir & "\faces\" & $sFileName );
- WEnd
- FileClose($hSearch)
- EndFunc
- Func Plural($i, $Unit)
- Local $Str
- $Str = $i & " " & $Unit
- If $i >= 2 OR $i = 0 Then
- $Str = $Str & "s"
- EndIf
- Return $Str
- EndFunc ;==>Plural
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement