Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <WinAPIEx.au3>
#include <Misc.au3>
Global $sOut = "C:\" ; Папка назначения
Global $szDrive, $szDir, $szFName, $szExt, $aPath
Global $hProgressProc = DllCallbackRegister('_ProgressProc', 'dword', 'uint64;uint64;uint64;uint64;dword;dword;ptr;ptr;ptr')
$Form1 = GUICreate("", 248, 46)
$Button1 = GUICtrlCreateButton("Выбрать файл", 16, 8, 219, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_FileCopy()
Switch @error
Case 0
MsgBox(64, "", "Файл скопирован")
Case 1
MsgBox(48, "", "Файл НЕ скопирован!")
EndSwitch
_Exit()
EndSwitch
WEnd
Func _FileCopy()
$sFileOpenDialog = FileOpenDialog("Выберите файл", @ProgramFilesDir & "\", "File (*.*)", 1 + 8 + 16)
If Not (@error) Then
$aPath = _PathSplit($sFileOpenDialog, $szDrive, $szDir, $szFName, $szExt)
If FileExists($sFileOpenDialog) And IsArray($aPath) Then
ProgressOn('_WinAPI_CopyFileEx', 'Copying...', '', -1, -1, 2)
_WinAPI_CopyFileEx($sFileOpenDialog, $sOut & $aPath[3] & $aPath[4], 0, DllCallbackGetPtr($hProgressProc))
If Not @error Then
Return SetError(0, 0, 0)
Else
_WinAPI_ShowLastError()
Return SetError(1, 0, 0)
EndIf
EndIf
EndIf
EndFunc ;==>_FileCopy
Func _ProgressProc($iTotalFileSize, $iTotalBytesTransferred, $iStreamSize, $iStreamBytesTransferred, $iStreamNumber, $iCallbackReason, $hSourceFile, $hDestinationFile, $iData)
Local $Percent = Round($iTotalBytesTransferred / $iTotalFileSize * 100)
If $Percent = 100 Then
ProgressSet($Percent, '', 'Complete')
Else
ProgressSet($Percent)
EndIf
If _IsPressed('1B') Then
Return $PROGRESS_CANCEL
Else
Return $PROGRESS_CONTINUE
EndIf
EndFunc ;==>_ProgressProc
Func _Exit()
DllCallbackFree($hProgressProc)
ProgressOff()
EndFunc ;==>_Exit
WinAPIEx.au3
|