#pragma compile(AutoItExecuteAllowed, True)
#include <Misc.au3>
#include <Timers.au3>
#include <GUIConstants.au3>
Global Const $sTitle = "Time-Out"
_Singleton($sTitle, 0)
Opt("MustDeclareVars", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
Opt("TrayAutoPause", 0)
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 0)
TrayItemSetOnEvent(TrayCreateItem("Сбросить"), "_Reset")
TrayCreateItem("")
TrayItemSetOnEvent(TrayCreateItem("Выход"), "_ExitScript")
TraySetOnEvent(-11, "_TimeWork")
TraySetState()
Global $nTimeWork = TimerInit(), $nMessage = TimerInit(), $nTimeOut, $nTimeDiff
Global $PID, $sMessage, $hClock, $hLabel
If $CmdLine[0] And Number($CmdLine[1]) > 0 Then
Global $iTime = $CmdLine[1]*60000
Else
Global $iTime = 45*60000
EndIf
While True
Sleep(1000)
If _Timer_GetIdleTime() > 600000 Then
$nTimeWork = TimerInit()
If ProcessExists($PID) Then ProcessClose($PID)
EndIf
If _IsWorkstationLocked() Then ContinueLoop
If WinExists(HWnd($hClock)) Then
$nTimeDiff = TimerDiff($nTimeOut)
GUICtrlSetData($hLabel, _GetTime($nTimeDiff))
If $nTimeDiff <= 600000 Then
GUICtrlSetColor($hLabel, 0xFF0000-0x10000*Round($nTimeDiff*255/600000))
EndIf
ElseIf Not ProcessExists($PID) Then
Switch StderrRead($PID)
Case 7
$nMessage = TimerInit()
Case 6
$hClock = GUICreate("Перерыв", 310, 90, -1, -1, BitOr($WS_CAPTION, $WS_SYSMENU), BitOr($WS_EX_TOPMOST, $WS_EX_COMPOSITED))
GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseWindow")
GUISetBkColor(0xFFFFFF)
GUISetFont(58)
WinSetTrans($hClock, "", 224)
$hLabel = GuiCtrlCreateLabel("00:00:00", 5, -1, -1, -1, $GUI_SS_DEFAULT_LABEL, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor($hLabel, 0xFF0000)
GUISetState(@SW_SHOW)
$nTimeOut = TimerInit()
ContinueLoop
EndSwitch
$nTimeDiff = TimerDiff($nTimeWork)
If $nTimeDiff > $iTime And TimerDiff($nMessage) > 60000 Then
$sMessage = "Время работы за компьютером: " & _GetTime($nTimeDiff) & @CRLF&@CRLF & "Пора сделать перерыв!"
$PID = Run(@AutoItExe & ' /AutoIt3ExecuteLine "ConsoleWriteError(MsgBox(4+64+262144,'''&$sTitle&''','''&$sMessage&'''))"', '', '', 4)
EndIf
EndIf
WEnd
Func _IsWorkstationLocked()
Local Const $DESKTOP_SWITCHDESKTOP = 0x0100
Local $Result = False
Local $hDesktop = DllCall('user32.dll', 'hwnd', 'OpenDesktop', 'str', 'Default', 'int', 0, 'int', 0, 'int', $DESKTOP_SWITCHDESKTOP)
If Not @error Then
$Result = DllCall('user32.dll', 'int', 'SwitchDesktop', 'hwnd', $hDesktop[0])
$Result = Not $Result[0]
DllCall('user32.dll', 'int', 'CloseDesktop', 'hwnd', $hDesktop[0])
EndIf
Return $Result
EndFunc ;==>_IsWorkstationLocked
Func _GetTime($Time)
$Time = Round($Time / 1000)
Local $iHour = Floor($Time / 3600)
Local $iMin = Floor(($Time - $iHour * 3600) / 60)
Local $iSec = $Time - $iHour * 3600 - $iMin * 60
Return StringFormat("%02d:%02d:%02d", $iHour, $iMin, $iSec)
EndFunc
Func _Reset()
$nTimeWork = TimerInit()
EndFunc
Func _TimeWork()
TraySetToolTip("Время работы: " & _GetTime(TimerDiff($nTimeWork)))
EndFunc
Func _CloseWindow()
GUIDelete()
$nTimeWork = TimerInit()
EndFunc
Func _ExitScript()
If ProcessExists($PID) Then ProcessClose($PID)
Exit
EndFunc