Has anyone ever worked with progress bars? I am wanting to use them, but I am practicing progressing the bar while reading a file. I use CreateFile then read it. Here's some code:
InitCommonControls();
HWND hwndPB;
HANDLE hFile; // handle of file
DWORD cb; // size of file and count of bytes read
LPCH pch; // address of data read from file
LPCH pchTmp; // temporary pointer
SendMessage(hwndPB, PBM_SETBARCOLOR, 0, RGB(16,26,150));
// Ensure that the common control DLL is loaded and create a
// progress bar along the bottom of the client area of the
// parent window. Base the height of the progress bar on
// the height of a scroll bar arrow.
InitCommonControls();
hwndPB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE, 0,
0,
400, 20,
hwnd, (HMENU) 0, 0, NULL);
// Open the file for reading, and retrieve the size of the file.
hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
if (hFile == (HANDLE) INVALID_HANDLE_VALUE)
return FALSE;
cb = GetFileSize(hFile, (LPDWORD) NULL);
// Set the range and increment of the progress bar.
SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, cb / 2048));
SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0);
// Parse the file.
pch = (LPCH) LocalAlloc(LPTR, sizeof(char) * 2048);
pchTmp = pch;
do {
ReadFile(hFile, pchTmp, sizeof(char) * 2048, &cb,
(LPOVERLAPPED) NULL);
// Advance the current position of the progress bar
// by the increment.
SendMessage(hwndPB, PBM_STEPIT, cb, 0);
} while (cb);
When I do that, though, it shows a progress bar, but no progress from STEPIT. I have tried:
SendMessage(hwndPB, PBM_STEPIT, 0, cb);
but it doesn't work either. What do I do? I got most of the code from MSDN!