FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to set a progressbar - range 1 - 5
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
How to set a progressbar - range 1 - 5
Posted: Fri Sep 18, 2009 07: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 (fw): Select all Collapse
#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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: How to set a progressbar - range 1 - 5
Posted: Fri Sep 18, 2009 04: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to set a progressbar - range 1 - 5
Posted: Fri Sep 18, 2009 04: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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to set a progressbar - range 1 - 5
Posted: Fri Sep 18, 2009 06: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 (fw): Select all Collapse
#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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to set a progressbar - range 1 - 5
Posted: Fri Sep 18, 2009 06: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

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: How to set a progressbar - range 1 - 5
Posted: Fri Sep 18, 2009 09: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to set a progressbar - range 1 - 5
Posted: Fri Sep 18, 2009 09: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

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to set a progressbar - range 1 - 5
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to set a progressbar - range 1 - 5
Posted: Sat Sep 19, 2009 04: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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to set a progressbar - range 1 - 5
Posted: Sat Sep 19, 2009 05:18 PM

Hello Antonio,
thank you.
I see. I will use TMeter for now.
Best regards,
Otto

Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: How to set a progressbar - range 1 - 5
Posted: Mon Sep 21, 2009 07: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 (fw): Select all Collapse
#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 (fw): Select all Collapse
@ 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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to set a progressbar - range 1 - 5
Posted: Mon Sep 21, 2009 08:24 AM
Hello Stefan,
Thank you very much.
Best regards,
Otto

Continue the discussion