* sample code oProg = CREATEOBJEcT("T_ProgressDlg") oProg.VISIBLE = .T. oProg.SetMessage("Searching...") FOR I=1 TO 100 IF m.I=50 THEN oProg.SetMessage("Searching... (halfway done!)") ENDIF oProg.SetFraction( m.I / 100 ) && Set progress bar level ( 0.0 .. 1.0 ) = INKEY(0.0125) && force a delay so that we can see screen. ENDFOR oProg.SetMessage("Done!") = INKEY(5.0) && delay again, to allow us to see the screen before it goes away RELEASE oProg *------------------------------------------------------------------------------ * The following classes for the progress dialog: * * T_ProgressDlg * A "no frills" progress (modeless) dialog. * Methods: * SetMessage( cTxt ) -- set message text * SetFraction( nPct ) -- set level on progress bar, parameter is value * representing level of completeness (0.0 .. 1.0) * SetStepSize( nVal ) -- set step size in progress for Step() method * Step() -- increment progress bar by value set by * SetFraction * * T_ThermBar * A class for implementing a "thermometer" bar (aka progress bar) * *------------------------------------------------------------------------------ DEFINE CLASS T_ProgressDlg AS form Height = 76 Width = 501 DoCreate = .T. AutoCenter = .T. AlwaysOnTop = .T. Caption = "Progress" ControlBox = .F. Closable = .F. MaxButton = .F. MinButton = .F. *-- Increment size for progress bar update. nstepsize = (0) Name = "T_ProgressDlg" ADD OBJECT lblmsg AS label WITH ; Caption = "Overall description of process", ; Height = 32, ; Left = 4, ; Top = 4, ; Width = 489, ; Name = "lblMsg" ADD OBJECT ctltherm AS T_ThermBar WITH ; Top = 48, ; Left = 8, ; Width = 484, ; Height = 20, ; SpecialEffect = 1, ; Name = "ctlTherm", ; shpThermBar.Name = "shpThermBar" *-- Set progress bar message PROCEDURE setmessage PARAMETERS cMsg THIS.lblMsg.CAPTION = m.cMsg ENDPROC *-- Set displayed fraction. PROCEDURE setfraction PARAMETERS nFract THIS.ctlTherm.Fraction = m.nFract ENDPROC *-- Increment fraction for the progress bar. PROCEDURE step THIS.ctlTherm.Fraction = THIS.ctlTherm.Fraction + THIS.nStepSize ENDPROC PROCEDURE setstepsize PARAMETERS nStepSize THIS.nStepSize = m.nStepSize ENDPROC PROCEDURE Init * - Address display problem when running under Vista where * the border of a window is sometimes missing. This * apparently happens whenever the BorderStyle is * overridden in a form. DO CASE CASE NOT OS(1) == "Windows 6.00" * No Vista, no problem. CASE EMPTY(SYS(1271, m.Thisform)) * No SCX form, no problem. CASE m.Thisform.SHOWWINDOW == 0 && In Screen. ACTIVATE WINDOW (m.Thisform.NAME) IN SCREEN NOSHOW CASE m.Thisform.SHOWWINDOW == 1 && In Top-Level Form. * LOCAL lcWindowName * lcWindowName = m.Thisform.GetTopLevelFormName() * ACTIVATE WINDOW (m.Thisform.Name) IN WINDOW (m.lcWindowName) NOSHOW OTHERWISE && As Top-Level Form. * Top-level forms are not affected. ENDCASE ENDPROC PROCEDURE Resize THIS.Width = MAX(200,THIS.Width) THIS.Height = 76 THIS.ctlTherm.Width = THIS.Width - THIS.ctlTherm.Left - 10 THIS.lblMsg.Width = THIS.Width - 2.0 * THIS.lblMsg.Left ENDPROC ENDDEFINE DEFINE CLASS T_ThermBar AS control Width = 342 Height = 27 BorderWidth = 1 SpecialEffect = 2 BackColor = RGB(255,255,255) fraction = 0 && Fraction to be represented by the thermometer bar. Name = "T_ThermBar" ADD OBJECT shpthermbar AS shape WITH ; Top = 2, ; Left = 2, ; Height = 20, ; Width = 320, ; BackStyle = 1, ; BorderStyle = 0, ; BackColor = RGB(0,0,128), ; Name = "shpThermBar" PROCEDURE fraction_assign LPARAMETERS vNewVal * LOCAL nBdr THIS.Fraction = MAX(MIN(m.vNewVal,1.0),0.0) * nBdr = THIS.BorderWidth + IIF(THIS.SpecialEffect==2,1,2) * THIS.shpThermBar.Width = (THIS.Width- (2.0*m.nBdr)) * THIS.Fraction THIS.Refresh() ENDPROC PROCEDURE borderwidth_assign LPARAMETERS vNewVal *To do: Modify this routine for the Assign method THIS.BorderWidth = m.vNewVal THIS.Refresh() ENDPROC PROCEDURE specialeffect_assign LPARAMETERS vNewVal *To do: Modify this routine for the Assign method THIS.SpecialEffect = m.vNewVal THIS.Refresh() ENDPROC PROCEDURE Refresh LOCAL nBdr nBdr = THIS.BorderWidth + IIF(THIS.SpecialEffect==2,1,2) THIS.shpThermBar.Left = m.nBdr THIS.shpThermBar.Top = m.nBdr THIS.shpThermBar.Height = THIS.Height - 2.0 * m.nBdr THIS.shpThermBar.Width = (THIS.Width- 2.0*m.nBdr) * THIS.Fraction ENDPROC PROCEDURE Init THIS.Refresh() ENDPROC PROCEDURE Resize THIS.Refresh() ENDPROC PROCEDURE mousepointer_assign LPARAMETERS vNewVal *To do: Modify this routine for the Assign method THIS.MOUSEPOINTER = m.vNewVal THIS.shpThermBar.MOUSEPOINTER = m.vNewVal ENDPROC ENDDEFINE && T_ThermBar