WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialogs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Various Progress Bar Samples

 Keywords:  Box aStatusBar HTML Application HTA DllCall CreateWindowExA msctls_progress32 Progress Status Graphical Animated Install Installation Bar BoxOpen BoxText Shell Operations Extender JavaScript Increment

Box Progress Bar

Title = "Installing - This may take up to 20 minutes (1200 seconds)"
Msg = "Seconds elapsed: "
Start = GetTickCount()
Run("Calc.exe","")
BoxOpen(Title,Msg)
While AppExist("Calc.exe",1,0)
   Elapsedms = GetTickCount() - Start
   ElapsedSec = Elapsedms / 1000
   BoxText(Msg:ElapsedSec)
   TimeDelay(1)
EndWhile
BoxShut()
Message("","Done")
Exit

aStatusBar Progress Bar

AddExtender("wwsop34i.DLL")
IntControl(1003,0,0,0,0) ; No WinBatch dialog
Title = "Installing __________"
Text = "This may take up to 20 minutes"
MaxRange = 1200
Run("Calc.exe","")
aStatusbar(0,Title,Text,MaxRange,0)
i = 0
While AppExist("Calc.exe",1,0)
   TimeDelay(1)
   i = i + 1
   aStatusbar(1,Title,Text,MaxRange,i)
EndWhile
aStatusbar(2,Title,Text,MaxRange,0)
Message("","Done")
Exit

DllCall CreateWindowExA msctls_progress32 Progress Bar

#DefineFunction udfProgressBarCreate(bartype,startx,starty,width,height,step,windowtitle)
   ;---------------------------------------------------------------------------------------------
   ;  Creates a progress bar
   ;  Returns the handle of the progress bar or -1 on failure
   ;
   ;   bartype = (4 = vertical, 3 = horizontal )
   ;   startx = x coordinate of upper left corner of progress bar
   ;   starty = y coordinate of upper left corner of progress bar
   ;   width = width of progress bar
   ;   height = height of progress bar
   ;   step = how many units to increment on each call to udfProgressBarTick
   ;   windowtitle = title of window in which to place the progress bar (use "" for main WinBatch window)
   ;
   ;  by GUI Guy (http://guiguy.wminds.com)


   dll=StrCat(DirWindows(1),"user32.dll")
   func="CreateWindowExA"
   winclass="msctls_progress32"
   hwnd=DllHwnd(windowtitle)
   hinst=DllHinst(windowtitle)

   smooth= 1
   vis= 268435456
   child= 1073741824
   hProgBar=DllCall(dll,long:func,long:0,lpstr:winclass,lpstr:"",long:bartype | smooth | vis | child,long:startx,long:starty,long:width,long:height,long:hwnd, long:0,long:hinst,long:0)
   If !hProgBar Then Return(-1)
   IntControl (22,hProgBar,1028,step,0)
   Return(hProgBar)
#EndFunction

#DefineFunction udfProgressBarTick(hProgBar)
   ;---------------------------------------------------------------------------------------------
   ;  Increments a progress bar (by amount specified when it was created)
   ;  Returns 1
   ;
   ;   handle = handle of progress bar to increment

   IntControl (22,hProgBar,1029,0,0)
   Return(1)
#EndFunction

title = "Installing"
BoxOpen( title, "" )
hProgBar = udfProgressBarCreate(3,75,75,500,25,5,title)
Run("Calc.exe","")
WindowOnTop( title, 1 )
i = 0
While AppExist("Calc.exe",1,0)
   TimeDelay(1)
   i = i + 1
   udfProgressBarTick( hProgBar )
EndWhile
Message("","Done")
Exit

WIL Dialog DllCall CreateWindowExA msctls_progress32 Progress Bar

IntControl(1002,0,0,0,0) ; No icon
IntControl(1003,0,0,0,0) ; No WinBatch Processing Window
IntControl(12,5,0,0,0) ; Terminate silently
Title = "Sample Progress"

ETA = 60
Elapsed = 0
ElapsedF = 1.0
Percent = 0
StartTime = GetTickCount()
Executable = "Calc.exe"

Run(Executable,"")

; Dialog constants
MSG_INIT = 0
MSG_TIMER = 1
DC_TITLE = 4
RET_DO_DEFAULT = -1

;--------------------------------------------------------------------------------------------------
; Create progress bar via DLL call

#DefineFunction CreateProgress(Title,solid,vertical,startx,starty,width,height)
hwnd = DllHwnd(Title)
hinst = DllHinst(Title)
u32 = StrCat(DirWindows(1),"user32.dll")
hprog = DllCall(u32,long:"CreateWindowExA",long:0,lpstr:"msctls_progress32",lpstr:"",long:vertical | solid | 268435456 | 1073741824,long:startx,long:starty,long:width,long:height,long:hwnd,long:0,long:hinst,long:0)
Return hprog
#EndFunction

;--------------------------------------------------------------------------------------------------
; Progress bar dialog callback procedure

#DefineSubRoutine DlgProgBarCallback(DlgProgBar_Handle,DlgProgBar_Message,DlgProgBar_ID,DlgProgBar_EventInfo,rsvd)
Switch DlgProgBar_Message
Case MSG_INIT
   DialogProcOptions(DlgProgBar_Handle,MSG_TIMER,10)
   hprog = CreateProgress(Title,0,0,12,70,400,15)
   Return RET_DO_DEFAULT
Case MSG_TIMER
   PE = Elapsed
   PP = Percent
   Done = !AppExist(Executable,1,0)
   If Done
      Percent = 100
   Else
      ElapsedF = (GetTickCount() - StartTime) / 1000.0
      Percent = Min(Elapsed * 1.0 / ETA * 100,100)
      Elapsed = Int(ElapsedF)
      Percent = Int(Percent)
      If Elapsed>PE Then DialogControlSet(DlgProgBar_Handle,007,DC_TITLE,Elapsed)
   EndIf
   If Percent>PP Then DialogControlSet(DlgProgBar_Handle,008,DC_TITLE,Percent)
   IntControl(22,hprog,1026,Percent,0) ; SendMessageA may be used if you have WinBatch 2006B or higher
   If Done
      If PP<100 Then TimeDelay(1)
      Exit
   EndIf
   Break
EndSwitch
Return RET_DO_DEFAULT
#EndSubRoutine

;--------------------------------------------------------------------------------------------------
; Progress bar dialog

DlgProgBarFormat = `WWWDLGED,6.1`

DlgProgBarCaption = Title
DlgProgBarX = -01
DlgProgBarY = -01
DlgProgBarWidth = 212
DlgProgBarHeight = 081
DlgProgBarNumControls = 009
DlgProgBarProcedure = `DlgProgBarCallback`
DlgProgBarFont = `DEFAULT`
DlgProgBarTextColor = `DEFAULT`
DlgProgBarBackground = `DEFAULT,DEFAULT`
DlgProgBarConfig = 0

DlgProgBar001 = `087,063,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
DlgProgBar002 = `015,003,078,010,STATICTEXT,DEFAULT,"Estimated seconds to complete :",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
DlgProgBar003 = `047,013,044,010,STATICTEXT,DEFAULT,"Seconds elapsed :",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
DlgProgBar004 = `023,023,070,010,STATICTEXT,DEFAULT,"Estimated percent complete :",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
DlgProgBar005 = `007,047,030,010,STATICTEXT,DEFAULT,"Running:",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
DlgProgBar006 = `093,003,016,010,VARYTEXT,ETA,DEFAULT,DEFAULT,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
DlgProgBar007 = `093,013,016,010,VARYTEXT,Elapsed,DEFAULT,DEFAULT,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
DlgProgBar008 = `093,023,016,010,VARYTEXT,Percent,DEFAULT,DEFAULT,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
DlgProgBar009 = `037,047,168,010,VARYTEXT,Executable,DEFAULT,DEFAULT,9,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

DlgProgBarButtonPushed = Dialog("DlgProgBar")
Exit

:CANCEL
IntControl(56,Executable,1,0,0) ; TerminateApp may be used if you have WinBatch 2006B or higher
Exit

HTML Application Progress Bar

#DefineFunction udfHTAProgress(text)
   title = "waiting" : StrReplace(TimeYmdHms(), ":", "")
   size  = 300
   splash_html =                            `<html><head><TITLE>` : title : `</TITLE>`
   splash_html = StrCat(splash_html, @CRLF, `<HTA:APPLICATION ID="my_splash_screen" APPLICATIONNAME="my_splash_screen" BORDER="dialog" CAPTION="no" SHOWINTASKBAR="no" SINGLEINSTANCE="yes" SYSMENU="yes" scroll="no" scrollFlat="yes" />`)
   splash_html = StrCat(splash_html, @CRLF, `<script>window.resizeTo(`, size, `,`, size, `); window.moveTo((screen.width-`, size, `)/2, (screen.height-`, size, `)/2);</script> `)
   splash_html = StrCat(splash_html, @CRLF, `<script language="JavaScript"> var time = 1; function increment() { time++; barre = ""; for(var i=0;i< time %% 19;i++) { barre = barre + '<img src="nothing.gif" width="10" height="10">  '; } document.getElementById('timer').innerHTML = "&nbsp; &nbsp;"+barre+"<br><center>Elapsed time: " + time + " seconds </center>"; window.setTimeout("increment()", 1000); return; } </script>`)
   splash_html = StrCat(splash_html, @CRLF, `</head><body style="background-color: #008080"><table height="100%%" width="100%%"><tr><td valign=middle style="background-color: #008080; color: #ffffff; FONT-FAMILY: Arial, Helvetica, Sans-serif; FONT-WEIGHT: Bold; FONT-STYLE: Normal; FONT-SIZE: 12pt;">`)
   splash_html = StrCat(splash_html, @CRLF, `<center>`, text, `</center><br><br><br><br><span id="timer"><br><br></span>`)
   splash_html = StrCat(splash_html, @CRLF, `</td></tr></table><script language="JavaScript"> window.setTimeout("increment()", 2000); </script></body></html>`)
   FilePut("waiting.hta", splash_html)
   Run(DirGet() : "waiting.hta", "")
   TimeDelay(1)
   winid1 = WinIdGet(title)
   WindowOnTop(winid1, 1)
   TimeDelay(1)
   FileDelete(DirGet() : "waiting.hta")
   Return winid1
#EndFunction

win = udfHTAProgress("Installation<br>Estimated time : 2500 seconds")

; Put your code here
  TimeDelay(10)

WinClose(win)
Exit

Article ID:   W18258
Filename:   Various Progress Bar Samples.txt
File Created: 2009:05:29:11:48:52
Last Updated: 2009:05:29:11:48:52