What IDE are you using?
Printable View
Vs2005.
Change its ID from IDC_PROGRESS1 to something other (for example IDC_PROGRESS_TEST)
Well although it may be one of the possible reasons, it was not the case of OP: he was working with a brand new project without any existent member variable.
I've just tested with a VS2008 (since I don't have 2005) and it seens to be a bug in IDE: after you drag/drop a progressbar to the dialog template (but only the first time!) and then tries to add a variable for it using the context menu - the menu item Add Variable is grayed. Only after you clicks somewhere on the properties window and go back the Add Variable item becomes enabled... :(
Still can't add variable after changing its name. Can I do it manually by adding it in MainDlg.h/cpp?
Edit: I just tried adding a progress control on another VS2005 project in resource view and "Add Variable" isn't grayed out. So I copied and pasted the variable definition as well as the DoDataExchange() definition from the other project over to MainDlg.h/cpp. Then, before the loop I showed the window using ShowWindow(SW_SHOW) and set the step using SetStep(100/number_of_iterations) and upon every loop iteration I called StepIt(). It works, except for non integer values of the step. Is there a better way of setting the step or must I manually set the position using SetPos((i+1)*(100/(float)number_of_iterations)) instead of StepIt()?
In answer to your original question, two solutions are given in the following article, a first solution which involves pumping messages between each iteration, and a second solution which involves threads:
Paul DiLascia, "C++ Q&A" column from the July 1998 issue of MSJ, http://www.microsoft.com/msj/0798/c0798.aspx
The article uses a static text box that displays a string like "Working on Iteration 15 out of 100", but can be modified easily if you would prefer to use a standard progress bar.
Mike
Set progress range to number_of_iterations and step it? :)Quote:
Is there a better way of setting the step or must I manually set the position using SetPos((i+1)*(100/(float)number_of_iterations)) instead of StepIt()?