computerwhiz
Programmer
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;
}