【已解决】执行解压文件,进度条百分比不能同步求助!
本帖最后由 h111666b 于 2023-8-6 20:59 编辑代码如下:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Global $hProgress, $hLabel
; 创建GUI窗口
$hGUI = GUICreate("进度条", 300, 100)
$hProgress = GUICtrlCreateProgress(10, 30, 280, 20)
$hLabel = GUICtrlCreateLabel("0%", 140, 60)
GUISetState(@SW_SHOW)
; 执行解压
Run("wimlib-imagex apply D:\win7.wim 1 G:\文件夹", "", @SW_HIDE)
; 更新进度条和百分比标签
For $i = 1 To 100
GUICtrlSetData($hProgress, $i)
GUICtrlSetData($hLabel, $i & "%")
Sleep(50)
Next
; 关闭GUI窗口
GUIDelete($hGUI)
此代码执行进度条和百分比,执行解压(RUN) 不会关联进度条和百分比,大文件和小文件解压时进度条和百分比都是一样的进度,不会快也不会慢,求助!
Global $hProgress, $hLabel, $hTitle = '进度条'
; 创建GUI窗口
$hGUI = GUICreate($hTitle, 300, 100)
$hProgress = GUICtrlCreateProgress(10, 30, 280, 20)
$hLabel = GUICtrlCreateLabel("100%", 140, 60, 100)
GUISetState(@SW_SHOW)
; 执行解压
RunCmd("wimlib-imagex apply win7.wim 1 文件夹")
; 关闭GUI窗口
Sleep(3000)
GUIDelete($hGUI)
Func RunCmd($sCommand)
Local $sOutput, $aSRE
Local $iPID = Run($sCommand, @ScriptDir, @SW_HIDE, 6)
While 1
If ProcessExists($iPID) = 0 Then
$hTitle = 'Done applying WIM image.'
WinSetTitle($hGUI, '', $hTitle)
GUICtrlSetData($hProgress, 100)
GUICtrlSetData($hLabel, 100 & "%")
ExitLoop
EndIf
$sOutput = StdoutRead($iPID, False, True)
$sOutput = BinaryToString($sOutput, 4)
If StringRegExp($sOutput, 'Applying|done', 0) Then
;ConsoleWrite($sOutput & @CRLF)
$aSRE = StringRegExp($sOutput, 'Creating.+?\((\d+?)\%\).+?$', 1)
If Not @error Then
If $hTitle <> 'Creating files' Then
$hTitle = 'Creating files'
WinSetTitle($hGUI, '', $hTitle)
EndIf
GUICtrlSetData($hProgress, $aSRE)
GUICtrlSetData($hLabel, $aSRE & "%")
EndIf
$aSRE = StringRegExp($sOutput, 'Extracting.+?\((\d+?)\%\).+?$', 1)
If Not @error Then
If $hTitle <> 'Extracting file data' Then
$hTitle = 'Extracting file data'
WinSetTitle($hGUI, '', $hTitle)
EndIf
GUICtrlSetData($hProgress, $aSRE)
GUICtrlSetData($hLabel, $aSRE & "%")
EndIf
$aSRE = StringRegExp($sOutput, 'Applying.+?\((\d+?)\%\).+?$', 1)
If Not @error Then
If $hTitle <> 'Applying metadata to files' Then
$hTitle = 'Applying metadata to files'
WinSetTitle($hGUI, '', $hTitle)
EndIf
GUICtrlSetData($hProgress, $aSRE)
GUICtrlSetData($hLabel, $aSRE & "%")
EndIf
EndIf
Sleep(100)
WEnd
EndFunc ;==>RunCmd
感谢高手 3131210 ,解决了
页:
[1]