#pragma compile(AutoItExecuteAllowed, true)
#RequireAdmin
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#include <StaticConstants.au3>
#include <WinAPIProc.au3>
#include <ScreenCapture.au3>
Global $timer, $Secs, $Mins, $Hour, $Time, $sTime, $TimeInf, $sPS, $sPD
Global $iPid, $iTM, $hTitleProc, $iProcWinH, $iProcWinW, $sPathSC = @TempDir & '\test.jpg'
$hGui = GUICreate('Секундомер', 500, 170, -1, -1, -1, $WS_EX_TOPMOST)
$TimeInf = GUICtrlCreateLabel('00:00:00:000', 8, 8, 330, 81, $SS_CENTERIMAGE + $SS_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 36, -1, -1, 'Impact')
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
Local $btStart = GUICtrlCreateButton('Старт', 392, 8, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
Local $btStop = GUICtrlCreateButton('Стоп', 392, 48, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
Local $sPathSS = GUICtrlCreateInput('', 8, 96, 325, 21)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
Local $sPathDD = GUICtrlCreateInput('', 8, 128, 325, 21)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
Local $sPathS = GUICtrlCreateButton('...', 392, 96, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
Local $sPathD = GUICtrlCreateButton('...', 392, 128, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
Global $iPS = GUICtrlCreatePic('', 20, 150, 100, 100)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
FileDelete('copy.txt')
_Timer_KillTimer($hGui, $iTM)
ProcessClose($iPid)
Exit
Case $sPathS
GUICtrlSetData($sPathSS, '')
$sPS = FileSelectFolder('Выбор копируемой папки', '', 0, '', $hGui)
If Not @error Then GUICtrlSetData($sPathSS, $sPS)
Case $sPathD
GUICtrlSetData($sPathDD, '')
$sPD = FileSelectFolder('Выбор папки назначения', '', 0, '', $hGui)
If Not @error Then GUICtrlSetData($sPathDD, $sPD)
Case $btStart
Local $aPosP = WinGetPos($hGui)
GUICtrlSetImage($iPS, '')
WinMove($hGui, '', $aPosP[0], $aPosP[1], $aPosP[2], $aPosP[3] - $iProcWinH)
FileDelete('copy.txt')
FileDelete($sPathSC)
If Not ProcessExists($iPid) Then
If FileExists($sPS) And FileExists($sPD) Then
GUICtrlSetData($TimeInf, '00:00:00:000')
FileWrite('copy.txt', "$Shell = ObjCreate('Shell.Application')" & @CRLF & "$Shell.NameSpace('" & $sPD & "').CopyHere('" & $sPS & "', 24)")
$timer = TimerInit()
$iTM = _Timer_SetTimer($hGui, 5, '_TIMER')
$iPid = Run(@AutoItExe & ' /AutoIt3ExecuteScript copy.txt')
If ProcessExists($iPid) Then
While 1
Local $ahWin = _WinAPI_EnumProcessWindows($iPid)
If Not @error Then
If Not StringInStr($ahWin[1][1], 'Autoit') Then
$hTitleProc = $ahWin[1][0]
Local $aPosC = WinGetPos($hTitleProc)
$iProcWinW = $aPosC[2]
$iProcWinH = $aPosC[3]
GUICtrlSetPos($iPS, 20, 170, $iProcWinW, $iProcWinH)
WinMove($hTitleProc, '', $aPosP[0] + 15, $aPosP[1] + $aPosP[3])
WinSetOnTop($hTitleProc, '', 1)
EndIf
ExitLoop
EndIf
WEnd
EndIf
FileDelete('copy.txt')
EndIf
EndIf
Case $btStop
FileDelete('copy.txt')
_Timer_KillTimer($hGui, $iTM)
ProcessClose($iPid)
GUICtrlSetData($TimeInf, '00:00:00:000')
$iPid = 0
Local $aPosP = WinGetPos($hGui)
GUICtrlSetImage($iPS, '')
WinMove($hGui, '', $aPosP[0], $aPosP[1], $aPosP[2], $aPosP[3] - $iProcWinH)
EndSwitch
WEnd
Func _TIMER($hWnd, $iMsg, $iIDTimer, $iTime)
Local $iProcC = Number(StringRegExpReplace(WinGetTitle($hTitleProc), '[^\d]', '\1'))
If $iProcC > 90 Then
_ProcessSuspend($hTitleProc, 1)
_ScreenCapture_CaptureWnd($sPathSC, $hTitleProc, 0, 0, -1, -1, False)
_ProcessSuspend($hTitleProc)
EndIf
If Not ProcessExists($iPid) Then
If FileExists($sPathSC) Then
WinMove($hGui, '', Default, Default, Default, 170 + $iProcWinH - 20)
GUICtrlSetImage($iPS, $sPathSC)
EndIf
FileDelete('copy.txt')
_Timer_KillTimer($hGui, $iTM)
$iPid = 0
EndIf
_TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs)
$Time = StringFormat('%02i:%02i:%02i:%03i', $Hour, $Mins, $Secs, StringRight(Int(TimerDiff($timer)), 3))
GUICtrlSetData($TimeInf, $Time)
EndFunc ;==>_TIMER
Func _ProcessSuspend($sProcess, $vProcSetState = False) ; $vProcSetState = True ; Приостанавливаем процесс
Local $hProcess, $iSucess, $iPid = ProcessExists($sProcess)
If Not $iPid Then Return SetError(1, 0, 0)
$vProcSetState = ($vProcSetState) ? 'NtSuspendProcess' : 'NtResumeProcess'
$hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, 0, $iPid)
If @error Then Return SetError(2, 0, 0)
$iSucess = DllCall('ntdll.dll', 'int', $vProcSetState, 'int', $hProcess)
_WinAPI_CloseHandle($hProcess)
If Not IsArray($iSucess) Then Return SetError(3, 0, 0)
Return 1
EndFunc ;==>_ProcessSuspend