Newbie: How do I make a progress dialog?
-
Hi, Do any of you know how to make a progress dialog? I am writing out my data in my CDocument class. I have a menu and a toolbar icon called "process and write out data". I want the progress dialog to update the progress ctrl as work is finished. I was hoping that the right way to do this is to manage the progress dialog updates in my cdocument, since that is where all my data is. Can you give me a little pseudocode that explains how this would work? Or should I be doing it another way? Thanks, Max
-
Hi, Do any of you know how to make a progress dialog? I am writing out my data in my CDocument class. I have a menu and a toolbar icon called "process and write out data". I want the progress dialog to update the progress ctrl as work is finished. I was hoping that the right way to do this is to manage the progress dialog updates in my cdocument, since that is where all my data is. Can you give me a little pseudocode that explains how this would work? Or should I be doing it another way? Thanks, Max
Most peoples gut reaction to progress bars is something like this... m_wndProgress.SetRange32(0,500); m_wndProgress.SetPos(0); for (int i=0;i<500;++i) { Sleep(50); // Just to slow this down for demo /* do work here */ m_wndProgress.SetPos(i); } However, if you drop this code into a button click handler in a dialog with a progress bar, you'll notice the dialog becomes unresponsive to any user actions such as closing the dialog. If processing your work takes enough time to require a progress bar, then it probably should allow the user to cancel or abort the activity. The easiest way to perform some lengthy processing while leaving the GUI thread free to respond to the user is to perform the processing in a separate worker thread. The worker thread then can post messages to the GUI thread to allow it to update the progress bar. This allows the GUI's message loop to process in a normal fashion. When we had the GUI thread performing the work as in the snippet above, message processing for the dialog had to wait for the loop to finish. Unresponsive GUI's are a good recipe for short tempers. Look up AfxBeginThread() for MFC threading Not quite pseudocode but I hope it helps get the wheels turning.
-
Hi, Do any of you know how to make a progress dialog? I am writing out my data in my CDocument class. I have a menu and a toolbar icon called "process and write out data". I want the progress dialog to update the progress ctrl as work is finished. I was hoping that the right way to do this is to manage the progress dialog updates in my cdocument, since that is where all my data is. Can you give me a little pseudocode that explains how this would work? Or should I be doing it another way? Thanks, Max