Page 1 of 1

Progress Bar on Dialog

Posted: Fri Jul 21, 2006 6:28 pm
by Bill Simmeth
Does anyone have an example of how to create a progress bar on a dialog? I have tried to define the dialog from a resource and also to create it from scratch. But, I have not been able to get either to function properly.

Thanks in advance...

Posted: Fri Jul 21, 2006 7:57 pm
by Bill Simmeth
Thank you. I have a sample running now. On a dialog, progress bar seems to behave a bit strange. Even though it reports a range of 0 to 10, it acts as though the range is 0,100.

Posted: Sat Jul 22, 2006 5:22 am
by Antonio Linares
Bill,

Would you mind to post your sample here so we can review it ?

Also you may review samples\TestProg.prg

Posted: Sat Jul 22, 2006 1:44 pm
by Bill Simmeth
Hi Antonio,

I have included code below. I used the samples\testprog.prg as a guide but needed to place the progress bar on a dialog, not the window. I was unable to do this using a dialog from a resource. So, I built the dialog dynamically.

I added a function to post the nMin, nMax and nPos of the bar so you see what happens.

Also, it looks like the default DLG_CHARPIX_H and DLG_CHARPIX_W need to be adjusted for FWPPC as they yield objects too large.

Thanks!

Code: Select all

#include "FWCE.ch"

FUNCTION Main()

LOCAL oWnd
DEFINE WINDOW oWnd TITLE "Progress"

@ 2, 2 BUTTON "Progress" SIZE 80, 25 ACTION ProgDialog()

ACTIVATE WINDOW oWnd

RETURN NIL

function ProgDialog()

   local oDlg, oPgr

   DEFINE Dialog oDlg TITLE "Progress Bars" FROM 5,12 TO 180, 230 PIXEL

   @ 1, 1 SAY oSay PROMPT "Testing" OF oDlg SIZE 150, 20

   @ 2, 0.9 PROGRESS oPgr OF oDlg SIZE 100, 15

   @ 3, 1 BUTTON "-" OF oDlg SIZE 20, 20  ;
      ACTION ( oPgr:nPosition -= 10 , BarStat( oSay, oPgr ) )

   @ 3, 4 BUTTON "+" OF oDlg SIZE 20, 20  ;
      ACTION ( oPgr:nPosition += 10 , BarStat( oSay, oPgr ) )

   ACTIVATE DIALOG oDlg ON INIT ( oPgr:nPosition := 50, BarStat( oSay, oPgr ) )

return nil

Procedure BarStat( oSay, oPgr )
 oSay:setText( Str( oPgr:nMin ) + ", " + Str( oPgr:nMax ) + ", " + Str( oPgr:nPos ) )
Return

Posted: Sat Jul 22, 2006 4:36 pm
by Antonio Linares
Bill,

Use Method SetRange() from ON INIT and check the bounds:

Code: Select all

   @ 3, 1 BUTTON "-" OF oDlg SIZE 20, 20  ; 
      ACTION ( if( oPgr:nPosition > 0, oPgr:nPosition -= 10, ), BarStat( oSay, oPgr ) ) 

   @ 3, 4 BUTTON "+" OF oDlg SIZE 20, 20  ; 
      ACTION ( if( oPgr:nPosition < 100, oPgr:nPosition += 10, ), BarStat( oSay, oPgr ) ) 

   ACTIVATE DIALOG oDlg ON INIT ( oPgr:SetRange( 0, 100 ), oPgr:nPosition := 50, BarStat( oSay, oPgr ) )