Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progress bars/ what a pain?? 1

Status
Not open for further replies.

computerwhiz

Programmer
May 1, 2002
28
US
I am trying to have my progress bar advance to the end only once. But I either end up scrolling several times or the progress bar won't scroll at all until the last read statement, and then filling the entire bar at once. I am reading in a file in chuncks, keeping count of total bytes read and the file size, I am trying to fill the progress bar a little at a time according to what percentage of the file I have read and processed.

Code:
BOOL ProcessFiles(HWND hwnd)
{
  HANDLE hFile;        // Handle of file
  DWORD cb;            // count of bytes read
  DWORD dwFileSize;    // Size of file
  int iTotBytes = 0;// Total bytes read
  LPCH pch;            // Address of data read from file
  LPCH pchTmp;         // Temporary pointer
  char lpszFile[512];
  
  for(int a = 0; a <= uintLBCount; a++)
  {
    SendMessage(hwndLB, LB_GETTEXT, a, (LPARAM) lpszFile);
    LPSTR Temp = strrchr(lpszFile, 0x05C)+1;
    SetWindowText(hwndSTS, Temp);

    hFile = CreateFile(
            lpszFile, GENERIC_READ, FILE_SHARE_READ,
            (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);

    if (hFile == (HANDLE) INVALID_HANDLE_VALUE)
        return FALSE;

    dwFileSize = GetFileSize(hFile, (LPDWORD) NULL);

    // Parse the file.
    pch = (LPCH) LocalAlloc(LPTR, 1);
    pchTmp = pch;
    while(ReadFile(hFile, pchTmp, 1,
          &cb, (LPOVERLAPPED) NULL))
    {
      if(cb)
      {
      iTotBytes += cb;
      // TODO: Write an error handler to check that all the
      // requested data was read.
      // slow down the Pbar temporarily to see it work
      //.
      for(int a = 0; a <= 1000; a++);
      //.
      // Include here code that parses the file.
      //.
      // Advance the current position of the
      // progress bar by the % of file read.
      SendMessage(hwndPB, PBM_SETPOS, (WPARAM)
                 ((iTotBytes/dwFileSize)*100), 0);
      }
      else break;
    }
    SetWindowText(hwndSTS, "...");
    SendMessage(hwndPB, PBM_SETPOS, (WPARAM)0, 0);
  }
  CloseHandle((HANDLE) hFile);
  return TRUE;
}
 
by the way I am using the default range setting of 0 to 100, I have not reset the step increment since I an not using stepit.
 
Your problem is probably here:

SendMessage(hwndPB, PBM_SETPOS, (WPARAM)((iTotBytes/dwFileSize)*100), 0);

The iTotBytes/dwFileSize is 0 because you are doing integer division. Either cast them to floats and then do the division or put (100*iTotBytes)/dwFileSize.
 
I feel so stupid, you are right and I relized it as soon as I saw your post. thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top