Re: Question on Progress dialog
"David Ching" <dc@remove-this.dcsoft.com> wrote in message
news:e02mj.5262$Rg1.3095@nlpi068.nbdc.sbc.com...
"Mikel" <mikel.luri@gmail.com> wrote in message
news:9b6cdb87-3ab7-4839-817c-516079b29fdd@m34g2000hsb.googlegroups.com...
Thanks for your response, Scott.
However, in your solution, how does the thread know if the user
pressed the "cancel" button?
The document (or whatever) that created the progress dialog could pass a
function pointer called OnCancelPressed() to the progress dialog. When
the Cancel button is pressed, the progress dialog calls that function.
That function then sets a flag or however it stops the worker thread. At
the same, the progress dialog shows "Cancel in progress, please wait" or
something because the worker thread might not stop immediately (it may
need to finish current operation before checking the flag). Once the
worker thread has ended, the document (or whatever) dismisses the progress
dialog.
-- David
Something to keep in mind is that, the function pointer could only point to
a static method, which will cancel all of the loadings at the same time (if
there are more than one going on at the same time, which I assume is
possible since you are loading in a worker thread, and have a modeless
progress dialog).
A more elegant solution (IMHO) would be to use a base class for any class
that want's to use your progress control, which has a virtual function
(perhaps even pure virtual) that gets called when the user presses the
cancel key.
class CProgressBarReceiver
{
public:
virtual void OnCancel() = NULL;
};
class CProgressDialog : public CDialog
{
CProgressDialog(CProgressBarReceiver *pNotifyParent......);
void SetNotifyParent(CProgressBarReceiver *pNotifyParent);
};
class CMyDocument : public CDocument, public CProgressBarReceiver
{
virtual void OnCancel() { CloseDialog(); KillThread();
CloseDocument(); }
};
AliR.