Jump to content

Progress bar for silently run program


Recommended Posts

Hi,

I'd like to show a progress bar for an operation performed by an external program my script is running silently, I want to show it in a GUI I created using the GUICtrlCreateProgress but I have no idea how to do it.

The important thing to point out is that there's no way of knowing how long the external program will run, as it is a file splitter and it depends on the size of file it splits and the split parts size.

Can someone point me in the right direction or give me an example how to do so?

This is my RunWait command:

RunWait($MYFILES1 & '\fsplit.exe -split ' & $Size & ' mb ' & $File & " -f " & $File & "." & $extension)

It uses multiple variables declared and set earlier in the script, how will I got about having the progress of that command shown using GUICtrlCreateProgress ? Is it possible?

Thank you.

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to comment
Share on other sites

RunWait pauses your script until fsplit.exe has finished, so i suggest using the style Marquee for the progressbar. Here a small example:

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <ProgressConstants.au3>


$Form1 = GUICreate("Form1", 545, 125, 5, 5);, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Button1 = GUICtrlCreateButton('&STOP Marquee', 5, 5, 200)
$Timer = GUICtrlCreateLabel('Zeit: ', 470, 5, 70)
$Progress1 = GUICtrlCreateProgress(0, 95, 545, 25, $PBS_MARQUEE)
$hProgress = GUICtrlGetHandle($Progress1)
_SendMessage($hProgress, $PBM_SETMARQUEE, True, 10)
GUISetState(@SW_SHOW)
$dtStart = TimerInit()


AdlibRegister('Timer', 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            If GUICtrlRead($Button1) = '&STOP Marquee' Then
                _SendMessage($hProgress, $PBM_SETMARQUEE, False, 10)
                GUICtrlSetData($Button1, '&Resume Marquee')
            Else
                _SendMessage($hProgress, $PBM_SETMARQUEE, True, 10)
                GUICtrlSetData($Button1, '&STOP Marquee')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Timer()
    Local $Time = TimerDiff($dtStart) / 1000
    Local $HOUR = Int($Time / 3600)
    Local $MIN = Int(($Time - $HOUR * 3600) / 60)
    Local $SEC = $Time - $HOUR * 3600 - $MIN * 60
    GUICtrlSetData($Timer, StringFormat("%02i:%02i:%02i", $HOUR, $MIN, $SEC))
EndFunc   ;==>Timer

If fsplit in console mode is writing progress to console you can use Run and StdoutRead for updating the real progress.

Link to comment
Share on other sites

 

4 hours ago, AutoBert said:

RunWait pauses your script until fsplit.exe has finished, so i suggest using the style Marquee for the progressbar. Here a small example:

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <ProgressConstants.au3>


$Form1 = GUICreate("Form1", 545, 125, 5, 5);, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Button1 = GUICtrlCreateButton('&STOP Marquee', 5, 5, 200)
$Timer = GUICtrlCreateLabel('Zeit: ', 470, 5, 70)
$Progress1 = GUICtrlCreateProgress(0, 95, 545, 25, $PBS_MARQUEE)
$hProgress = GUICtrlGetHandle($Progress1)
_SendMessage($hProgress, $PBM_SETMARQUEE, True, 10)
GUISetState(@SW_SHOW)
$dtStart = TimerInit()


AdlibRegister('Timer', 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            If GUICtrlRead($Button1) = '&STOP Marquee' Then
                _SendMessage($hProgress, $PBM_SETMARQUEE, False, 10)
                GUICtrlSetData($Button1, '&Resume Marquee')
            Else
                _SendMessage($hProgress, $PBM_SETMARQUEE, True, 10)
                GUICtrlSetData($Button1, '&STOP Marquee')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Timer()
    Local $Time = TimerDiff($dtStart) / 1000
    Local $HOUR = Int($Time / 3600)
    Local $MIN = Int(($Time - $HOUR * 3600) / 60)
    Local $SEC = $Time - $HOUR * 3600 - $MIN * 60
    GUICtrlSetData($Timer, StringFormat("%02i:%02i:%02i", $HOUR, $MIN, $SEC))
EndFunc   ;==>Timer

If fsplit in console mode is writing progress to console you can use Run and StdoutRead for updating the real progress.

Well, fsplit does usually run in a command prompt, I intend to eventually set it to start hidden but it does show some kind of progress in the command line console by default, so I think maybe StdoutRead can be used but I'm not sure.

The progress it shows is not percentage but actually text line telling which part is is being created.

Anyway, here's a sample of the GUI I created, I need the progress to be shown in it and I need the OK button to become clickable only after the fsplit command ended.

#Region ### START Koda GUI section ### Form=
$Form13 = GUICreate("TITLE", 615, 500, 192, 124)
GUISetBkColor(0x0871AB)
GUISetIcon("UCC.ico")
$Text = GUICtrlCreateLabel("LINE1" & @CRLF & "LONG TEXT" & @CRLF & @CRLF & "LINE" & @CRLF & "TEXT" & @CRLF & "LINE" & @CRLF & @CRLF & "TEXT" & @CRLF & @CRLF, 15, 15, 600, 230)
GUICtrlSetFont($Text, 10, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor($Text, 0xC5D3ED)
$Text2 = GUICtrlCreateLabel("LINE" & @CRLF & "TEXT" & @CRLF & "Part of the " & "TEXT" & " (UCC) Tool by " & "AUTHOR" & @CRLF & "LINE" & @CRLF & @CRLF & _
"STEP " & "Number" & ": Splitting " & "Filename" & " into " & "Size" & " Parts" & @CRLF & @CRLF & "Please Wait..." , 15 , 230, 500,170)
GUICtrlSetFont($Text2, 10, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor($Text2, 0xC5D3ED)
$Logo = GUICtrlCreatePic(@TempDir & "\UCC\GUILogo.jpg", 490, 5, 130, 130)
GUICtrlSetState($Logo, $GUI_DISABLE)
$SplitProgressL = GUICtrlCreateLabel("Progres Bar:", 15, 400, 520, 15)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetColor(-1, 0xC5D3ED)
$SplitProgress = GUICtrlCreateProgress(15, 415, 580, 15)
$btnOK = GUICtrlCreateButton("OK", 510, 470, 100, 23)
GUISetState() ; display the GUI
#EndRegion ### END Koda GUI section ###
While 1
            $Msg = GUIGetMsg()
            Sleep(10)
            Switch $Msg
                Case $GUI_EVENT_CLOSE, $btnOK
                    GUIDelete()
                    ExitLoop
            EndSwitch
        WEnd

I of course removed all the variable I actually used from this sample for the example purpose, anyway, I would I go about making that GUI progress bar work with the fsplit command? 

I don't really care the type of progress bar animation, as long as it is shown within the GUI window and it works.

BTW, I'm attaching an image showing the fsplit CMD console output.

28582953138_95f920326f_o.png

 

Edited by VollachR
Added more info

Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...