update progress bar in a popup dialog
This is an interesting design problem. For example, if the progress
bar is associated with the document, it should in principle be another
"view", even if it isn't CView-derived, it has the same logical
properties as a view. In that case, the way I would do it is to call
upon the document to create the progress bar dialog (modeless, not
modaless--that's a term Jeff Richter invented to designate a funny
kind of dialog box back in Win16). Thus, the only entity that knows
about the progress dialog is the document. The document then does its
document-like computations and every so often notifies the dialog to
update itself. If you have a worker thread, this gets a bit tricky,
because there is no easy way to send notifications to a document other
than via WM_COMMAND, unless you adopt a scheme like I use for sending
timer notifications to a document (which is to create a hidden window
as an intermediary...see my essay on getting timer events to a dialog,
and realize that you can use the same sort of trick to have a worker
thread notify a document).
Generally, you don't create the dialog on the OnInitialUpdate handler
unless the dialog is actually recording the initialization for the
view (note that if you are initializing the document contents, this
should not be done from the *view* update, but from OnNewDocument).
Various controls respond to state change requests in different ways.
Some update themselves immediately; some wait for the message pump to
come around and handle WM_PAINT. Thus, if you do the lengthy
initialization in your GUI thread, and do a SetPos(), the control may
or may not update. If it doesn't, just call UpdateWindow to force the
redraw.
joe
Quote:
>Hi, Joe and A Jax:
>thanks to both of you.
>I tried the following steps, seems it works, may not be
>the best way to implement:
>1: define CProgressDialog* m_pProgressDialog in the
>CAnalyzerView
>2: create a modaless dialog in CAnalyzerView::initUpdate()
>3: pass the m_pProgressDialog to m_pMyDoc
>4: LenthyCalculation() will call SetPos in the FOR loop
>but myself do not like the idea of user-defined object in
>MyDoc needs to know the dialog object in View class.
>I will spend more time to try the suggestions you made.
>thanks a lot
>Belinda
>>-----Original Message-----
>>Timers and PeekMessage are ugly solutions. Largely
>throwbacks to Win16
>>days. I try to avoid putting anything as heavy-duty as a
>PeekMessage
>>in a compute-bound thread. Threads are so easy it seems a
>waste of
>>time to build complex solutions.
>> joe
>>On Sun, 21 Oct 2001 15:53:20 -0400, "A Jax"
>>>Chapter 12 of Programming Microsoft Visual C++ Fifth
>Edition explains how to
>>>do this with Timers and ::PeekMessage.
>>>> Hi, please help
>>>> when I click a button on a form, it calls a user-
>defined
>>>> function. the function is a length calculation repeated
>>>> many times in a FOR loop. how can I update the progress
>>>> bar in a popup dialog.
>>>> As shown in the following code, in the view class I
>have
>>>> two members. I defined m_pMyDoc as a pointer to the Doc
>>>> class, m_ProgressDialog as a derived class of CDialog,
>it
>>>> contains only a CProgressCtrl bar m_ProgressBar and the
>>>> OK/Cancel button.
>>>> when I called the DoModal(), I can initlize and display
>>>> the progress bar no problem, seems like the
>>>> LenthyCalculation() will not start untill I click
>Cancel
>>>> in the progress dialog.
>>>> ??? What I need to do to let it reflect the actual
>>>> progress in LenthyCalculation(). so the
>LenthyCalculation
>>>> () can call the SetPos of m_ProgressBar
>>>> ??? do I need use a seperate thead
>>>> ??? any sample working code
>>>> Thanks
>>>> Belinda
>>>> ---------------------------------------------------
>>>> void CAnalyzerView::OnRadioButtonCalculate()
>>>> {
>>>> m_ProgressDialog.DoModal() ;
>>>> m_pMyDoc.LenthyCalculation();
>>>> UpdateView();
>>>> }
>>>> void CAnalyzerDoc::LenthyCalculation()
>>>> {
>>>> for (int i = 0; i< aBigNumber; i++)
>>>> {
>>>> doSomething(); //takes a few minutes
>>>> }
>>>> }
>>Joseph M. Newcomer [MVP]
>>Web: http://www3.pgh.net/~newcomer
>>MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
>>.
Joseph M. Newcomer [MVP]
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm