Jump to content

GUICtrlCreateProgress wrongly used?


MariusN
 Share

Recommended Posts

Am i doing this correct? Seems like the "bar" takes forever to complete...

(I'm using "GUICtrlCreateProgress" b.t.w )

For $I = 0 To 100 Step 25
      GUICtrlSetData($pb, $I)
      RunWait('TAKEOWN /f ' & '"' & $Select0 & '"' & ' /r /d y', "", @SW_HIDE)
     Next

PS: If i do a straight

RunWait('TAKEOWN /f ' & '"' & $Select0 & '"' & ' /r /d y')

......it takes about half the time to finish...

thank folks...

Link to comment
Share on other sites

Runwait() waits for the run to complete. What you do in the loop above is to run it 4 times. If the takeown program returns progress data to the console you could read the stdout stream, but as not many console programs do this there is just no way to estimate the overall runtime.

As a workaround create the progres control with the $PBS_MARQUEE flag set to indicate that something is happening, here's a piece of pseudo-code:

#include <SENDMESSAGE.AU3>

$c_Progress = GUICtrlCreateProgress(9, 35, 340, 17, $PBS_MARQUEE)
$h_Progress = GUICtrlGetHandle($c_Progress)

_SendMessage($h_Progress, $PBM_SETMARQUEE, True, 0)
RunWait('TAKEOWN /f ' & '"' & $Select0 & '"' & ' /r /d y', "", @SW_HIDE) 
_SendMessage($h_Progress, $PBM_SETMARQUEE, False, 0)
Edited by KaFu
Link to comment
Share on other sites

Runwait() waits for the run to complete. What you do in the loop above is to run it 4 times. If the takeown program returns progress data to the console you could read the stdout stream, but as not many console programs do this there is just no way to estimate the overall runtime.

As a workaround create the progres control with the $PBS_MARQUEE flag set to indicate that something is happening, here's a piece of pseudo-code:

#include <SENDMESSAGE.AU3>

$c_Progress = GUICtrlCreateProgress(9, 35, 340, 17, $PBS_MARQUEE)
$h_Progress = GUICtrlGetHandle($c_Progress)

_SendMessage($h_Progress, $PBM_SETMARQUEE, True, 0)
RunWait('TAKEOWN /f ' & '"' & $Select0 & '"' & ' /r /d y', "", @SW_HIDE)
_SendMessage($h_Progress, $PBM_SETMARQUEE, False, 0)

Thx KaFu...will def look into this. I had the same idea with the "stdout"....tried it, but didnt work with "takeown.exe" from Win7...
Link to comment
Share on other sites

I'm still having trouble with long "progress bars"...This is my current code. believe that a command gets excecuted 4x when using GUICtrlCreateProgress,

is there a way around it? Some kind of "if then" or something? Any ideas would be apreciated folks...

This is my current code --->

For $I = 0 To 100 Step 10
   GUICtrlSetData($pb, $I)
   $copy = DirCopy($Select1, @HomeDrive & "" & "Junk", 1)
  Next
Edited by MariusN
Link to comment
Share on other sites

DirCopy() is a blocking function, it returns only when the copy operation has finished 100% (or failed :D).

If you want to implement progress feedback you'll have to do it on your own. Melba23's excellent comes in handy there :oops:...

#include <guiconstantsex.au3>
#include <progressconstants.au3>

; #include <array.au3>
#include <recfilelisttoarray.au3>

GUICreate("My GUI Progressbar", 220, 100, 100, 200)
$progressbar = GUICtrlCreateProgress(10, 30, 200, 20)
GUICtrlSetColor(-1, 32250); not working with Windows XP Style
$button = GUICtrlCreateButton("Start", 75, 70, 70, 20)
GUISetState()

Do
    $msg = GUIGetMsg()
    If $msg = $button Then
        GUICtrlSetData($button, "Stop")
        $a_Files = _RecFileListToArray(@WindowsDir & "Help", "*", 1, 1, 0, 1)
        ; _ArrayDisplay($a_Files)
        For $i = 1 To $a_Files[0]
            GUICtrlSetData($progressbar, ($i / $a_Files[0])*100)
            FileCopy(@WindowsDir & "Help" & $a_Files[$i], @ScriptDir & "Help" & $a_Files[$i], 9)
        Next
        GUICtrlSetData($button, "Start")
    EndIf
Until $msg = $GUI_EVENT_CLOSE
Edited by KaFu
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...