SHARE
TWEET

AutoIt Desktop Sobriety Counter

a guest Aug 8th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ButtonConstants.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <StaticConstants.au3>
  4. #include <WindowsConstants.au3>
  5. #Include <WinAPI.au3>
  6. #include <EditConstants.au3>
  7. #include <Timers.au3>
  8. #include <MsgBoxConstants.au3>
  9. #include <Date.au3>
  10. #Include <GDIPlus.au3>
  11. #include <MsgBoxConstants.au3>
  12. #include <Array.au3>
  13.  
  14. ; 04/09/2018 - last time used?
  15. ; 5/04/2018
  16. ; 6/25/2018 - 7PM
  17. Global Const $SobrietyDate = "2018/06/25 19:00:00"
  18. Global $Pictures[0]
  19.  
  20.  
  21. If WinExists("Sobriety Counter", "") Then
  22.     MsgBox($MB_ICONERROR, "Error", "Sober counter is already running.")
  23.     Exit(1)
  24. EndIf
  25.  
  26. FindPictures()
  27.  
  28.  
  29. Global $hGui, $hCounter, $hTitle, $hHelpBtn, $strLastCounter
  30. Opt("TrayIconHide", 1)
  31.  
  32.  
  33. $hGui = GUICreate("Sobriety Counter", 324, 56, @DesktopWidth - 323, 0, $WS_POPUP, $WS_EX_LAYERED, WinGetHandle("Program Manager"))
  34. GUISetBkColor(0xABCDEF)
  35. $hCounter = GUICtrlCreateInput("", 0, 24, 330, 28, $ES_READONLY)
  36. GUICtrlSetFont($hCounter, 12, 800, 0, "MS Sans Serif")
  37. $hTitle = GUICtrlCreateLabel("Sobriety Counter", 0, 0, 150, 24)
  38. GUICtrlSetFont($hTitle, 12, 800, 0, "MS Sans Serif")
  39. GUICtrlSetColor($hTitle, 0xFFFFFF)
  40. $hHelpBtn = GUICtrlCreateButton("HELP!", 130, 0, 57, 25)
  41. GUICtrlSetFont($hHelpBtn, 8, 800, 0, "MS Sans Serif")
  42. GUICtrlSetColor($hHelpBtn, 0xFF0000)
  43. _WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF, 255)
  44. GUISetState(@SW_SHOW)
  45.  
  46. _Timer_SetTimer($hGui, 2000, "_TimerUpdateCounter")
  47. UpdateCounter()
  48.  
  49. Local $ShowingPics = false, $picTimer
  50.  
  51. While 1
  52.     $nMsg = GUIGetMsg()
  53.     Switch $nMsg
  54.         Case $GUI_EVENT_CLOSE
  55.             Exit
  56.         Case $hHelpBtn
  57.             If $ShowingPics = false Then
  58.                 $picTimer = _Timer_SetTimer($hGui, 5000, "_TimerFaces")
  59.                 UpdateFaces()
  60.                 $ShowingPics = True
  61.             Else
  62.                 SplashOff()
  63.                 _Timer_KillTimer($hGui, $picTimer)
  64.                 $ShowingPics = False
  65.             EndIf
  66.  
  67.     EndSwitch
  68. WEnd
  69. ;
  70.  
  71.  
  72.  
  73.  
  74. Func _TimerFaces($hWnd, $Msg, $iIDTimer, $dwTime)
  75.     UpdateFaces()
  76. EndFunc   ;==>_TimerFaces
  77.  
  78. Func UpdateFaces()
  79.     Local $strFilename = GetRandomPicture()
  80.    Local $siz = ImageSize( $strFilename )
  81.     if($siz[0] > (@DesktopWidth - 25)) OR($siz[1] > (@DesktopHeight - 25)) Then
  82.         $siz[0] = $siz[0] / 1.4
  83.         $siz[1] = $siz[1] / 1.4
  84.     EndIf
  85.  
  86.     SplashImageOn("Is this what you want?", $strFilename, $siz[0], $siz[1])
  87. EndFunc   ;==>UpdateFaces
  88.  
  89. Func _TimerUpdateCounter($hWnd, $Msg, $iIDTimer, $dwTime)
  90.     UpdateCounter()
  91. EndFunc   ;==>_TimerUpdateCounter
  92.  
  93.  
  94. Func UpdateCounter()
  95.     Local $Seconds = _DateDiff('s', $SobrietyDate, _NowCalc())
  96.     Local $Days = 0, $Hours = 0, $Minutes = 0
  97.     Local $Str, $i
  98.  
  99.     $i = Int($Seconds / 86400)
  100.     If $i >= 1 Then
  101.         $Seconds = $Seconds - (86400 * $i)
  102.         $Days = $i
  103.     EndIf
  104.  
  105.     $i = Int($Seconds / 3600)
  106.     If $i >= 1 Then
  107.         $Seconds = $Seconds - (3600 * $i)
  108.         $Hours = $i
  109.     EndIf
  110.  
  111.     $i = Int($Seconds / 60)
  112.     If $i >= 1 Then
  113.         $Seconds = $Seconds - (60 * $i)
  114.         $Minutes = $i
  115.     EndIf
  116.  
  117. $Str = Plural($Days, "Day") & ", " & Plural($Hours, "Hour") & ", and " & Plural($Minutes, "Minute")
  118. If $strLastCounter <> $Str Then
  119.     $strLastCounter = $Str
  120.     GUICtrlSetData($hCounter, $Str)
  121.     EndIf
  122. EndFunc   ;==>UpdateCounter
  123.  
  124.  
  125. Func ImageSize($file)
  126.     Local $t[2]
  127.  
  128.     _GDIPlus_Startup()
  129.     Local $hImage = _GDIPlus_ImageLoadFromFile($file)
  130.     If @error Then
  131.         MsgBox(16, "Error", "Does the file exist? " & $file)
  132.         Exit 1
  133.     EndIf
  134.  
  135.  
  136.     $t[0] = _GDIPlus_ImageGetWidth($hImage)
  137.     $t[1] = _GDIPlus_ImageGetHeight($hImage)
  138.     _GDIPlus_ImageDispose($hImage)
  139.     _GDIPlus_ShutDown()
  140.     Return $t
  141. EndFunc   ;==>ImageSize
  142.  
  143.  
  144.  
  145. Func GetRandomPicture()
  146.    Local $rand = Random(0, UBound($Pictures)-1, 1 )
  147.    Local $pic = $Pictures[$rand]
  148.  
  149.    Return $pic;
  150. EndFunc
  151.  
  152.  
  153. Func FindPictures()
  154.     Local $hSearch = FileFindFirstFile(@ScriptDir & "\faces\*.jpg" )
  155.     Local $sPictures[0], $sFileName = "", $iResult = 0
  156.  
  157.     If $hSearch = -1 Then
  158.         Return False
  159.     EndIf
  160.  
  161.     While 1
  162.         $sFileName = FileFindNextFile($hSearch)
  163.         If @error Then ExitLoop
  164.         _ArrayAdd( $Pictures, @ScriptDir & "\faces\" & $sFileName );
  165.      WEnd
  166.  
  167.     FileClose($hSearch)
  168. EndFunc
  169.  
  170.  
  171. Func Plural($i, $Unit)
  172.     Local $Str
  173.     $Str = $i & " " & $Unit
  174.     If $i >= 2 OR $i = 0 Then
  175.         $Str = $Str & "s"
  176.     EndIf
  177.     Return $Str
  178. EndFunc   ;==>Plural
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top