Using GetFileSizeEX() and progress bars

Hi,

I'm using the following code to get the file size in bytes of my 'in file'. I'm using GetFileSizeEX as I'd like to support files larger than 4GB:

1
2
3
4
5
6
LARGE_INTEGER fileSize;
if (! ::GetFileSizeEx(sourceFile, &fileSize))
{
  // Error in file size
}
SendMessage(pHwndPrgBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));


The problem, PBM_SETRANGE takes two integer parameters, how can I downsize the fileSize variable to something realistic that will fit in the range?

I'm not fussed if it's divisible by 100 or not as latter on I'm doing this:

1
2
size = fread(data, sizeof *data, sizeof data / sizeof *data, sourceFile);
SendMessage(pHwndPrgBar, PBM_STEPIT, 0, size);


I guess whatever I do to fileSize to get a value that fits in the range I'll have to do to size so that it'll progress evenly.

I thought this would be a common sort of hurdle but don't see anything on the Internet that explains how you make a file's size fit into the progress bar range.

Thank you,
AJM.
Last edited on
There isn't.

A progress bar is a percent object. If you choose the progress bar to have, say, 100 units, then to calculate how many bytes to read per bump on the progress bar, take the file size and divide it by 100.

filesize = 12498
progress bar length = 100
number of bytes to read before bumping the progress bar by 1 = 12498 / 100 = 124.98 --> 125

Because of rounding, you'll have to just set the progress bar to 100% when you've wholly read the file.

Hope this helps.
Topic archived. No new replies allowed.