2011-01-21

Using the CTL32 ProgressBar from FoxyPreviewer

Foxypreviewer.app is a collection of classes. Inside the APP there are several classes, that you can access directly using VFP.
Recently I received a request to show how the ctl32 progressbar could be used directly.

Thats's really simple ! The key command is NEWOBJECT(), that allows us to access classes from an external EXE or APP.
First of all the author of this gem, the CTL32 progressbar is Carlos Alloatti. For the complete information on how to use it, please go directly to the CTL32 website: www.ctl32.com.ar

Usage:

 

=dotherm(90, "caption", "titlebar") && shows the regular progressbar with 90%



 

=dotherm(-1, "caption", "titlebar") && the -1 value in the 1st parameter brings the marquee cool effect



 

=dotherm() && turns off the progressbar

 

 

save the code below as dotherm.prg

* dotherm.prg
* =dotherm(90, "texto label", "titulo")
* =dotherm(-1, "teste2", "titulo") && continuo
* =dotherm() && desliga

lparameters tnpercent, tclabeltext, tctitletext
if not pemstatus(_screen, "othermform", 5)
   _screen.addproperty("othermform", "")
endif
if empty
(tnpercent)
   try
      _screen
.othermform.release()
   catch
   endtry
   _screen
.othermform = null
   return
endif


if type
("_screen.othermform.therm") <> "o"
   do createtherm
endif
local
lothermform as form
lothermform = _screen.othermform
if not empty(tclabeltext)
   lothermform.thermlabel.
caption = tclabeltext
endif
if
not empty(tctitletext)
   lothermform.
caption = tctitletext
endif
if
tnpercent = -1
   lothermform.therm.marquee = .t.
else
   if
lothermform.therm.marquee = .t.
      lothermform.therm.marquee = .f.
   endif
   lothermform.therm.value = tnpercent
endif
lothermform.visible = .t.

return


procedure
createtherm
local loform as form
loform = createobject("form")
_screen.othermform = loform
local lnborder, lithermheight, lithermwidth, lithermtop, lithermleft
lnborder = 7
with loform as form
   .scalemode = 3 && pixels
   .height = 48
   .
halfheightcaption = .t.
   .
width = 300
   .
autocenter = .t.
   .
borderstyle = 3 && fixed dialog
   .controlbox = .f.
   .
closable = .f.
   .
maxbutton = .f.
   .
minbutton = .f.
   .
movable = .f.
   .
alwaysontop = .t.
   .
allowoutput = .f.

   .
newobject("therm","ctl32_progressbar", "pr_ctl32_progressbar.vcx", locfile("foxypreviewer.app"))
   .
newobject("thermlabel", "label")

   .thermlabel.
visible = .t.
   .thermlabel.
fontbold = .t.
   .thermlabel.
top = 4
   .thermlabel.
width = .width - (lnborder * 2)
   .thermlabel.
alignment = 2 && center
   lithermheight = .height - (lnborder * 2) - .thermlabel.height
   lithermwidth = .width - (lnborder * 2)
   .
visible = .t.
endwith
lithermtop = lnborder + 20
lithermleft = lnborder
with loform.therm
   .
top = lithermtop
   .
left = lithermleft
   .
height = lithermheight
   .
width = lithermwidth
   .marqueespeed = 30
   .marqueeanimationspeed = 30
   .
visible = .t.
   .
caption = ""
endwith
endproc

7 comments:

  1. Great job Cesar !

    But, does not affect the performance FoxyPreviewer?

    Thank's.
    Hi Riva,
    Using progress bars will always affect the performance. FoxyPreviewer has a property "lSilent". If you set it to true, no progress bars will be shown.
    This sample shows how you can use the progressbar in your application, even if you are not using a report !

    ReplyDelete
  2. Cesar very good!

    Already translated into Spanish in PortalFox:

    -- Usando el CTL32 ProgressBar de FoxyPreviewer --
    http://www.portalfox.com/article.php?sid=2725

    Muchas gracias Luis Maria !
    Saludos
    Cesar

    ReplyDelete
  3. Very nice Cesar Thanks to sharing with us!
    Hey Soykan,
    Thanks for your continuous support!

    ReplyDelete
  4. Hi Cesar

    I think you should not advise people to do this. Separate the progress bar as a stand alone class. Use this new class separately in apps and from inside foxypreviewer.

    Mike
    Hello Mike,
    Thanks for passing by at my blog, and for your comment. :-D
    I truly agree with you. But Since the vast majority of FoxyPreviewer users are beginners, I just wanted to offer them a very simple way for them to have the progressbars. The progressbar is a free control created by Carlos Alloatti, available at www.ctl32.com.ar . Using it needs some basic OOP knowledge, that not all the users of FoxyPreviewer have so far. Apart from that, FoxyPreviewer is a class library that stores EVERYTHING in a single APP. That's the only file people need to distribute to use it. Absolutely no change in their projects structure.
    Cheers
    Cesar

    ReplyDelete
  5. I'm sorry to disagree, but certainly you are not saying that the code above requires less OOP knowledge? I doubt any FoxPro users are so beginner. Giving people a crutch is no way to help them improve. It is better to show people the best ways to do things.
    Mike,
    That's your mission, not mine. Each person tries to give his contribution. YOU are the teacher who tells everybody how to do things, not me. My VFP skills are very limited, and I don't feel like teaching things to people. I just show some things that I think are cool. That simple.
    You could easily have left it out of your .APP (which is not a class library, but an App) and included the DoTherm.prg as a wrapper around Carlos' original progressbar.

    Of course I could, but as I said before, I don't want to leave anything for people to deal with. People who are interested can go to the sources and get whatever they want. My goal is to have JUST ONE SINGLE file, that simple. This is a tool UNDER DEVELOPMENT, and receives contant updates. Updating a single file is easier. And that's all I can handle.

    Having another copy of Carlos' progress bar in my app is bloatware to me.

    Mike
    Of course ! I never had the desire to make something perfect, like you do. I'm not trying to create perfect codes. I'm just trying to create a useful tool. I always knew that any of my tools would be eligible to be used by you.
    This is NOT a another copy of Carlos' CTL32 classes. The latest releases of the CTL32 brings a pack full of classes and resources. The class that I'm distributing in my APP is one of the very first versions, and probably the most light weight for that purpose.
    I've seen many beginners bringing questions asking how to use the CTL32 classes. I just wanted to provide to the users of my APP an easy way for them to have access to that class. I never recommended people to use my APP just to get to the CTL32 classes. I'm very sorry if I passed that impression.
    Regards
    Cesar

    ReplyDelete
  6. DEFINE CLASS TERMOMETRO AS form
    SHOWWINDOW = 1
    TOP = 196
    LEFT = 142
    HEIGHT = 75
    WIDTH = 460
    AUTOCENTER = .T.
    BORDERSTYLE = 2
    CLOSABLE = .F.
    CONTROLBOX = .F.
    MAXBUTTON = .F.
    MINBUTTON = .F.
    TITLEBAR = 0
    ALWAYSONTOP = .F.
    IPERCENTAGE = 0
    IBASIS = 0
    CCURRENTTASK = ''
    SHPTHERMBARMAXWIDTH = 422
    CTHERMREF = ""
    NIMAGEN = 1
    CONTADOR = 0
    NAME = "thermometer"
    ADD OBJECT LBLTITLE AS LABEL WITH FONTNAME = "ARIAL", FONTSIZE = 8, FONTBOLD = .T., BACKSTYLE = ;
    0, BACKCOLOR = RGB(192, 192, 192), CAPTION = "", HEIGHT = 16, LEFT = 16, TOP = 11, WIDTH = ;
    429, WORDWRAP = .F., NAME = "lblTitle"
    ADD OBJECT LBLTASK AS LABEL WITH FONTNAME = "ARIAL", FONTSIZE = 7, BACKSTYLE = 0, BACKCOLOR = ;
    RGB(192, 192, 192), FORECOLOR = RGB(0, 0, 0), CAPTION = "", HEIGHT = 50, LEFT = 16, TOP = ;
    29, WIDTH = 429, WORDWRAP = .T., NAME = "lblTask"
    * color del cuadro donde se pone la barra
    ADD OBJECT CUADRO AS TEXTBOX WITH ENABLED = .F., BORDERSTYLE = 0, BACKSTYLE = 1, ;
    DISABLEDBACKCOLOR = RGB(0, 0, 0), SPECIALEFFECT = 0, HEIGHT = 18, LEFT = 11, TOP = 50, ;
    WIDTH = 437, NAME = "Cuadro"
    * color de la barra que crece (Verde "Windows7")
    ADD OBJECT SHPTHERMBAR AS SHAPE WITH BORDERSTYLE = 0, FILLCOLOR = RGB(0, 128, 32), FILLSTYLE = 0, ;
    HEIGHT = 12, LEFT = 14, TOP = 53, WIDTH = 0, NAME = "shpThermBar"
    ADD OBJECT LBLPERCENTAGE AS LABEL WITH FONTNAME = "ARIAL", FONTSIZE = 7, BACKSTYLE = 0, ;
    CAPTION = "0%", FORECOLOR = RGB(0, 0, 0), HEIGHT = 15, LEFT = 425, TOP = 34, WIDTH = 30, ;
    NAME = "lblPercentage"
    **
    PROCEDURE complete
    PARAMETER M.CTASK
    PRIVATE ISECONDS
    IF PARAMETERS()=0
    M.CTASK = 'Terminado'
    ENDIF
    THIS.UPDATE(100, M.CTASK)
    ENDPROC
    **
    PROCEDURE UpdateTaskMessage
    PARAMETER CTASK
    THIS.CCURRENTTASK = M.CTASK
    THIS.LBLTASK.CAPTION = THIS.CCURRENTTASK
    ENDPROC
    **
    PROCEDURE update
    PARAMETER IPROGRESS, CTASK
    IF PARAMETERS()>=2 .AND. TYPE('m.cTask')='C'
    THIS.CCURRENTTASK = M.CTASK
    ENDIF
    IF .NOT. THIS.LBLTASK.CAPTION==THIS.CCURRENTTASK
    THIS.LBLTASK.CAPTION = THIS.CCURRENTTASK
    ENDIF
    IF THIS.IBASIS0
    M.IPERCENTAGE = INT((M.IPROGRESS/THIS.IBASIS)*100)
    ELSE
    M.IPERCENTAGE = M.IPROGRESS
    ENDIF
    M.IPERCENTAGE = MIN(100, MAX(0, M.IPERCENTAGE))
    IF M.IPERCENTAGE=THIS.IPERCENTAGE
    RETURN
    ENDIF
    THIS.SHPTHERMBAR.WIDTH = INT((THIS.SHPTHERMBARMAXWIDTH)*M.IPERCENTAGE/100)
    THIS.LBLPERCENTAGE.CAPTION = ALLTRIM(STR(M.IPERCENTAGE, 3))+'%'
    THIS.IPERCENTAGE = M.IPERCENTAGE
    ENDPROC

    PROCEDURE Init
    PARAMETER CTITLE, NOBARRA
    DO CTL32.PRG
    DO SYSTEM.APP
    THIS.LBLTITLE.CAPTION = IIF(EMPTY(M.CTITLE), '', M.CTITLE)
    LOCAL CCOLOR
    IF FONTMETRIC(1, "MS Sans Serif", 8, '')13 .OR. FONTMETRIC(4, "MS Sans Serif", 8, '')2 .OR. ;
    FONTMETRIC(6, "MS Sans Serif", 8, '')5 .OR. FONTMETRIC(7, "MS Sans Serif", 8, '')11
    THIS.SETALL('FontName', "tahoma")
    ENDIF
    M.CCOLOR = RGBSCHEME(1, 2)
    M.CCOLOR = 'rgb('+SUBSTR(M.CCOLOR, AT(',', M.CCOLOR, 3)+1)
    *THIS.BACKCOLOR = &CCOLOR
    THIS.BackColor=RGB(255,255,255)
    IF NOBARRA
    THIS.LBLPERCENTAGE.VISIBLE = .F.
    THIS.SHPTHERMBAR.VISIBLE = .F.
    THIS.CUADRO.VISIBLE = .F.
    THIS.HEIGHT = 75
    ENDIF
    ENDPROC

    a CTL32_progressbar, ¿Q es lo que debo cambiar? ya que supongo que no será mucho

    Gracias

    3008102508

    ICQ 279 364 380
    Face: +573008102508
    MSN: eres_un_vago@hotmail.com
    Mail: eres_un_vago@yahoo.es
    Whatsapp: +573008102508
    Skype: eres_un_vago

    ReplyDelete
  7. DEFINE CLASS TERMOMETRO AS form
    SHOWWINDOW = 1
    TOP = 196
    LEFT = 142
    HEIGHT = 75
    WIDTH = 460
    AUTOCENTER = .T.
    BACKCOLOR = RGB(240,240,240)
    BORDERSTYLE = 2
    CLOSABLE = .F.
    CONTROLBOX = .F.
    MAXBUTTON = .F.
    MINBUTTON = .F.
    TITLEBAR = 0
    ALWAYSONTOP = .F.
    IPERCENTAGE = 0
    IBASIS = 0
    CCURRENTTASK = ''
    SHPTHERMBARMAXWIDTH = 422
    CTHERMREF = ""
    NIMAGEN = 1
    CONTADOR = 0
    NAME = "thermometer"
    ADD OBJECT SHPTHERMBAR AS CTL32_PROGRESSBAR WITH height = 18, left = 11, top = 50, width = 437, ;
    ctlmaximum = 100, ctlminimum = 1, ctlStyle = 3, ctlBackColor = RGB(0,0,0), ;
    ctlBarColor = RGB(0,255,128), ctlBorderColor = RGB(0,0,0), name = "shpThermBar"
    ADD OBJECT LBLTITLE AS LABEL WITH FONTNAME = "ARIAL", FONTSIZE = 8, FONTBOLD = .T., BACKSTYLE = ;
    0, BACKCOLOR = RGB(240, 240, 240), CAPTION = "", HEIGHT = 16, LEFT = 16, TOP = 11, WIDTH = ;
    429, WORDWRAP = .F., NAME = "lblTitle"
    ADD OBJECT LBLTASK AS LABEL WITH FONTNAME = "ARIAL", FONTSIZE = 7, BACKSTYLE = 0, BACKCOLOR = ;
    RGB(240, 240, 240), FORECOLOR = RGB(0,0,0), CAPTION = "", HEIGHT = 50, LEFT = 16, TOP = ;
    29, WIDTH = 429, WORDWRAP = .T., NAME = "lblTask"
    * color del cuadro donde se pone la barra
    ADD OBJECT CUADRO AS TEXTBOX WITH ENABLED = .F., BORDERSTYLE = 0, BACKSTYLE = 1, ;
    DISABLEDBACKCOLOR = RGB(0,000,000), SPECIALEFFECT = 0, HEIGHT = 18, LEFT = 11, TOP = 50, ;
    WIDTH = 437, NAME = "Cuadro"
    * color de la barra que crece
    *ADD OBJECT SHPTHERMBAR AS SHAPE WITH BORDERSTYLE = 0, FILLCOLOR = RGB(65,135,252), FILLSTYLE = 0, ;
    HEIGHT = 12, LEFT = 14, TOP = 53, WIDTH = 0, NAME = "shpThermBar"
    ADD OBJECT LBLPERCENTAGE AS LABEL WITH FONTNAME = "ARIAL", FONTSIZE = 7, BACKSTYLE = 0, ;
    CAPTION = "0%", FORECOLOR = RGB(0,0,0), HEIGHT = 15, LEFT = 425, TOP = 34, WIDTH = 30, ;
    NAME = "lblPercentage"

    PROCEDURE Init
    PARAMETER CTITLE, NOBARRA
    DO CTL32.PRG
    DO SYSTEM.APP
    THIS.LBLTITLE.CAPTION = IIF(EMPTY(M.CTITLE), '', M.CTITLE)
    LOCAL CCOLOR
    IF FONTMETRIC(1, "MS Sans Serif", 8, '')13 .OR. FONTMETRIC(4, "MS Sans Serif", 8, '')2 .OR. ;
    FONTMETRIC(6, "MS Sans Serif", 8, '')5 .OR. FONTMETRIC(7, "MS Sans Serif", 8, '')11
    THIS.SETALL('FontName', "tahoma")
    ENDIF
    M.CCOLOR = RGBSCHEME(1, 2)
    M.CCOLOR = 'rgb('+SUBSTR(M.CCOLOR, AT(',', M.CCOLOR, 3)+1)
    *THIS.BACKCOLOR = &CCOLOR
    THIS.BackColor=RGB(240,240,240)
    IF NOBARRA
    THIS.LBLPERCENTAGE.VISIBLE = .F.
    THIS.SHPTHERMBAR.VISIBLE = .F.
    THIS.CUADRO.VISIBLE = .F.
    THIS.HEIGHT = 75
    ENDIF
    ENDPROC
    **
    ENDDEFINE


    There's a problem: the form windows is transparent, I don't know why. Who's help me??

    ReplyDelete