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

Function progress_bar
Copy      Help
function# hDlg message wParam lParam
if(hDlg) goto messages

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

;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 ""
;DIALOG EDITOR: "" 0x2010900 "" ""

;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
,SendMessage hpb PBM_SETRANGE ti range<<16
,SetTimer hDlg 1 timerperiod 0

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

,s.setwintext(id(5 hDlg))

,case WM_COMMAND goto messages2
sel wParam
,case IDOK
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
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?

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)