Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Progress bar
#1
Hi there!
In the archive files there is a progress bar dialog that works with a timer. The code is this:

Function progress_bar
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("barra_progresso" &barra_progresso 0 0 0 0 0 0 0 0 "\\nsn-intra.net\EEFS\GS\sn ss gnoc\projects\tim\Menu TIM\miscellaneous\icons\timmenu-2.ico")) ret

;BEGIN DIALOG
;0 "" 0x10C80A48 0x100 0 0 198 27 "Update do MenuTIM"
;3 msctls_progress32 0x54000000 0x4 8 10 136 12 ""
;5 Static 0x54000000 0x0 150 10 44 12 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010900 "" ""

ret
;messages
;you can change these values
int range=300
int step=1
int timerperiod=1 ;;should be >=50

int- ti
int hpb=id(3 hDlg)
str s
sel message
,case WM_INITDIALOG
,SendMessage hpb PBM_SETRANGE ti range<<16
,SetTimer hDlg 1 timerperiod 0

,case WM_TIMER
,ti+step
,SendMessage hpb PBM_SETPOS ti 0
,if(ti<range) s.format("%i %%" 100*ti/range)
,else
,,s="Completed"
,,KillTimer hDlg 1
,, DT_Ok hDlg ;;close dialog

,s.setwintext(id(5 hDlg))

,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

I want to know if I could use this progress bar to see the actual progress of something like copying a file.
Let's say I have something like this:

Function test
Code:
Copy      Help
OnScreenDisplay "Copying file 1"
cop "c:\test\test.xls" "c:\test2\test.xls"
OnScreenDisplay "File 1 - Done!"; wait 1
OnScreenDisplay "Copying file 2"
cop "c:\test\test2.xls" "c:\test2\test2.xls"
OnScreenDisplay "File 2 - Done!"; wait 1

And have the progress bar Dialog give me the progress on that code. Can I do that?

Thanks!!
#2
Probably will need 2 threads.
Thread 1 does something, eg copies files.
Thread 2 shows a dialog with a progress bar control.
Thread 1 (or thread 2) periodically somehow calculates how mush % of the work is done and sends PBM_SETPOS messages to the control.
Can be in single thread, if it is possible to process messages while doing that something.
Programming with progress bars usually is difficult because in most cases you don't know exactly the speed of that something, etc. I cannot give a general solution.


Forum Jump:


Users browsing this thread: 1 Guest(s)