title: Progressbar Range and position, how to handle big numbers in C++?
body: <p>Trying to implement windows Progressbar showing progress of download in bytes with big numbers, but am unable to do it correctly. </p>
  
  <p>For a download of 2.5gb if I do following, it ends short of the full range when download is complete.</p>
  
  <pre><code>double dlSize = getDlSize();
  unsigned int pbRange = (unsigned int)( dlSize / 3000 );
  SendMessage( hProgressbar, PBM_SETRANGE, 0, MAKELPARAM( 0, pbRange ) );
  </code></pre>
  
  <p>and then set new position at each download callback as :</p>
  
  <pre><code>double dlBytes = bytesDownloaded();
  unsigned int newIncrement = (unsigned int)( dlBytes / 3000 );
  SendMessage( hProgressbar, PBM_DELTAPOS, (WPARAM)newIncrement, 0 );
  </code></pre>
  
  <p>This is a very noobish implementation, and I don't want fall in the xy situation, So my question is what is the correct way to implement a progressbar with big numbers in tune of 2-5GBs in bytes ?</p>
  
  <hr>
  
  <p>I tried both approaches suggested below by @msandiford and @NikBougalis, by taking the width of the progressbar in account and by using percentage instead of actual number, I even combined both, but in all cases the newIncrement always comes out 0, maybe that's because dlSize is always lower( in double newIncrement comes out something like 1.15743e+007, type cast it and its 0 ). </p>
  
  <p><strong>What else I can do ?</strong></p>
  
  <p>New Code combining both approaches:</p>
  
  <p>EDIT 2:
  Added few checks to the code as I was constantly getting 0 for newIncrement, looks like its working now, not sure how well:</p>
  
  <pre><code>GetClientRect(hProgressbar, &amp;pbRCClient);
  pbWidth = pbRCClient.right - pbRCClient.left; // (pbWidth  its a global variable)
  unsigned int pbRange = pbRCClient.right - pbRCClient.left;
  SendMessage( hProgressbar, PBM_SETRANGE, 0, MAKELPARAM( 0, pbRange ) );
  </code></pre>
  
  <p>and while updating :</p>
  
  <pre><code>double dlSize = getDlSize();
  double doubleIncrement = ( ( dlSize * pbWidth ) / totalSize );
  
  unsigned int newIncrement;
  
  if ( (unsigned int)doubleIncrement &lt; 1 )
  {
      blockFill += doubleIncrement;
  
      if ( (unsigned int)blockFill &gt; 1 )
      {
          newIncrement = ( unsigned int )blockFill;
          SendMessage( hProgressbar, PBM_DELTAPOS, (WPARAM)newIncrement, 0 );
          blockFill = 0;
      }
  }
  else
  {
      newIncrement = ( unsigned int )( doubleIncrement );
      SendMessage( hProgressbar, PBM_DELTAPOS, (WPARAM)newIncrement, 0 );
      //blockFill = 0;
  }
  </code></pre>
  
  <p>EDIT 3 : Looks like its still finishing early.</p>