How to set a progressbar - range 1 - 5

How to set a progressbar - range 1 - 5

Postby Otto » Fri Sep 18, 2009 7:37 am

I have problems with PROGRESSBAR.
I use the following sample of the FIVEWIN samples and try to find out how to make a progressbar for the following setup.

The range should be: from 1 to 5 and the step 1

Would be someone so kind to help me.
Thanks in advance
Otto


Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oDlg, oProg1
   
   DEFINE DIALOG oDlg TITLE "Progress Bars"
   
   @ 1, 1 PROGRESS oProg1 SIZE 80, 12

   @ 3,  9 BUTTON "Ok" ACTION oDlg:End()
   
   oDlg:bStart = { || Increase( oProg1 ) }
   
   ACTIVATE DIALOG oDlg CENTER ;
      ON INIT ( oProg1:SetRange( 1, 5 ), oProg1:SetStep( 1 ) )
   
return nil  
//----------------------------------------------------------------------------//

function Increase( oProg1  )

   local n
   
   for n = 1 to 5
      oProg1:StepIt()
      oProg1:SetPos( n )
      Sleep( 5 )
      SysRefresh()
   next
   
return nil      
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to set a progressbar - range 1 - 5

Postby James Bott » Fri Sep 18, 2009 4:35 pm

Otto,

I think sleep() is in milliseconds. Change it to 500 for 5 seconds.

Or you can use waitSeconds( nSeconds ) or inkey( nSeconds ) instead of sleep().

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: How to set a progressbar - range 1 - 5

Postby Otto » Fri Sep 18, 2009 4:51 pm

Hello James,

thank you for your answer.
Not sleep is the problem. The problem I face is range.
If I select 0,100 and then a For next with 1 to 111 like in the FWH sample the progressbar works.
But with another range (min/max) for me it is not working.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to set a progressbar - range 1 - 5

Postby Antonio Linares » Fri Sep 18, 2009 6:02 pm

Otto,

In your example, if you increase the sleep time then you will see that it only does 4 steps. If you change it this way, then it performs five steps:
Code: Select all  Expand view

#include "FiveWin.ch"

function Main()

   local oDlg, oProg1
   
   DEFINE DIALOG oDlg TITLE "Progress Bars"
   
   @ 1, 1 PROGRESS oProg1 SIZE 80, 12

   @ 3,  9 BUTTON "Ok" ACTION oDlg:End()
   
   oDlg:bStart = { || Increase( oProg1 ) }
   
   ACTIVATE DIALOG oDlg CENTER ;
      ON INIT ( oProg1:SetRange( 0, 5 ), oProg1:SetStep( 1 ) )
   
return nil  
//----------------------------------------------------------------------------//

function Increase( oProg1  )

   local n
   
   for n = 1 to 5
      oProg1:StepIt()
      oProg1:SetPos( n )
      Sleep( 400 )
      SysRefresh()
   next
   
return nil      
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How to set a progressbar - range 1 - 5

Postby Otto » Fri Sep 18, 2009 6:38 pm

Hello Antonio,
I tried your code but this is the result:
I would like that the progressbar is at the end full.
Best regards,
Otto

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to set a progressbar - range 1 - 5

Postby James Bott » Fri Sep 18, 2009 9:04 pm

Otto,

That seems to be a problem when using themes as it works fine without them.

As a workaround you could try setting the range smaller, like maybe 3.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: How to set a progressbar - range 1 - 5

Postby Otto » Fri Sep 18, 2009 9:23 pm

Hello James,
thank you. I tried so many values. The best result I got to use 100 and to calculate the percents.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to set a progressbar - range 1 - 5

Postby Enrico Maria Giordano » Sat Sep 19, 2009 12:16 pm

Otto wrote:I would like that the progressbar is at the end full.


It's full for me using 0, 5, with or without themes.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to set a progressbar - range 1 - 5

Postby Antonio Linares » Sat Sep 19, 2009 4:52 pm

Using Windows Vista or Windows 7 it fails if using themes. This is an issue that we already discussed in these forums. Please see a proposed "solution" that works:
viewtopic.php?p=63307#p63307
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How to set a progressbar - range 1 - 5

Postby Otto » Sat Sep 19, 2009 5:18 pm

Hello Antonio,
thank you.
I see. I will use TMeter for now.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to set a progressbar - range 1 - 5

Postby StefanHaupt » Mon Sep 21, 2009 7:57 am

Hello Otto,

Otto wrote: I will use TMeter for now.
Otto


to get a similar look you can use this version of metpaint.c, where the bar is painted. I changed it to use a gradient.

Code: Select all  Expand view
#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>

void WindowBoxIn( HDC hDC, RECT * pRect );
void Gradient( HDC hDC, RECT * rct, COLORREF crStart, COLORREF crEnd, BOOL bVertical );

static far BYTE cChars[ 81 ];

//----------------------------------------------------------------------------//

HARBOUR HB_FUN_METERPAINT( PARAMS )         //  hWnd, hDC, nActual, nTotal, porcentage, Texto, lporcentage, 4 colores, font
{
   HWND hWnd = ( HWND ) _parnl( 1 );
   HDC  hDC  = ( HDC ) _parnl( 2 );
   RECT rc, rcClient, rcG;
   WORD wCol, wRow, wRight;
   WORD wPercent = _parni(  5 );
   char * cText  = _parc(   6 );
   int iPorcent  = _parl(   7 );
   DWORD dwPane  = _parnl(  8 );
   DWORD dwText  = _parnl(  9 );
   DWORD dwBar   = _parnl( 10 );
   DWORD dwBText = _parnl( 11 );
   HFONT hFont   = ( HFONT ) _parnl( 12 );
   HFONT hOldFont;
   int nLenght  = 0;
   SIZE nSizes;

   cChars[ 0 ] = 0;

   if( hFont )
      hOldFont = ( HFONT ) SelectObject( hDC, hFont );

   if( cText[ 0 ] )
   {
      lstrcpy( ( char * ) cChars, cText );
      nLenght = lstrlen( ( char * ) cChars );
      cChars[ nLenght++ ] = ' ';

   }
   if( iPorcent )
   {
      if( wPercent == 100 )
      {
          cChars[ nLenght     ] = '1';
          cChars[ nLenght + 1 ] = '0';
      }
      else
      {
          cChars[ nLenght     ] = ' ';
          cChars[ nLenght + 1 ] = ( wPercent < 10 ? ' ' : ( BYTE ) ( wPercent / 10 )   + '0' );
      }
      cChars[ nLenght + 2 ] = ( BYTE ) ( wPercent % 10 )   + '0';
      cChars[ nLenght + 3 ] = '%';
      nLenght += 4;
   }

   GetClientRect( hWnd, &rc );

   rcClient.top    = rc.top;
   rcClient.left   = rc.left;
   rcClient.bottom = rc.bottom - 1;
   rcClient.right  = rc.right  - 1;

   GetTextExtentPoint( hDC, ( char * ) cChars, nLenght, &nSizes );

   wCol   = ( ( rc.right - rc.left ) / 2 ) - ( nSizes.cx / 2 );
   wRow   = ( ( rc.bottom - rc.top ) / 2 ) - ( nSizes.cy / 2 );
   wRight = rc.right;
   rc.top++;
   rc.left++;
   rc.bottom = rc.bottom-2; //--;
   rc.right = ( WORD ) --rc.right * wPercent / 100;

   SetBkColor( hDC, dwBar );
   //Gradient (hDC,&rc, dwBar, dwPane, TRUE);
   SetTextColor( hDC, dwBText );
   SetBkMode (hDC,1);
   ExtTextOut( hDC, wCol, wRow, ETO_CLIPPED | ETO_OPAQUE, &rc, ( char * ) cChars, nLenght, 0 );

   WindowBoxIn( hDC, &rcClient );

   SetBkColor( hDC, dwPane );
   Gradient (hDC,&rc, RGB (255,255,255), dwBar, TRUE);
   SetTextColor( hDC, dwText );

   rc.left  = rc.right + 1;
   rc.right = wRight - 1;

   //if( wPercent <= 100 )
      ExtTextOut( hDC, wCol, wRow, 0, &rc, ( char * ) cChars, nLenght, 0 );
   //else
   //  ExtTextOut( hDC, wCol, wRow, 0, &rc, ( char * ) cChars, nLenght, 0 );

   SetBkMode (hDC,2);
   if( hFont )
      SelectObject( hDC, hOldFont );

   _retni( 0 );
}

//----------------------------------------------------------------------------//
 


Code: Select all  Expand view
@ 02, 120 METER oMeter var nStep total 100 OF oWnd:oMsgBar size 170,15 pixel color nRGB( 231, 242, 255 ),CLR_BLACK
 
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: How to set a progressbar - range 1 - 5

Postby Otto » Mon Sep 21, 2009 8:24 am

Hello Stefan,
Thank you very much.
Best regards,
Otto

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 75 guests