View Single Post
Old Nov 3rd, 2005, 7:23 PM   #54
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Here are some problems:
1. I hope that the posting swalllowed your indenting and your program doesn't actually look like that

2. The code
      SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
      SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 20, 0);
To initialise the progress bar needs to go after you create the progress bar, otherwise you are just sending messages to a random window. This also means your progress bar has no range or step being set. I suspect this is your main problem.

3. In your WM_COMMAND section you are using an hdc that hasn't been set yet. Note that the hdc variable is used and set in the WM_PAINT case, but this is during a different call of your MainWndProc (your MainWndProc is called anew for each message). This means you are trying to draw lines on an uninitialised DC which at best will do nothing, at worst will crash your program (or your machine).
I added
hdc = GetDC(hwnd);
and
ReleaseDC(hwnd, hdc);
at the start and end of the WM_COMMAND case section to get this to work.

4. Instead of your timing loops use
Sleep(1000);
This is much friendlier to the rest of the system (probably doesn't matter for this program as it only runs for a few seconds).


As a side note, you might find it easier if you split up your MainWndProc into separate functions and called them from a simple case statement. This would make it more obvious that the different message handlers can't share variables unless they are global.
The Dark is offline   Reply With Quote