Hi everyone,
I'm having troubles with pausing and continuing MFC Thread.For test
purposes I've created in my MFC Dialog application a progress Bar
Control, a Start Button and a Stop Button.The idea is to start the
progress Bar Control by clicking on the Start Button and I would like
to pause (Stop Button) the process at anytime and continue it when I
click on the Start Button.I had a look at the following homepage:
http://www.flounder.com/workerthreads.htm and frankly speaking I still
don't understand how:CEvent(CreateEvent), WaitForSingleObject
(WAIT_OBJECT_0), AfxBeginThread, Postmessage, etc... collaborate with
each other.
Here is for example what should occur when one the Start Button
clicks:
void CProgressbarExampleDlg::OnBnStart()
{
int i, count;
count=0;
while(count < 170)
{
for (i=0;i<30;i++)
{
m_ProgressBarCtrl.SetPos(i+10);
Sleep(10);
}
count ++;
}
}
Should the code on the OnBnStart() function be the Workerthread?I
should start it with AfxBeginThread right?Where should I create the
handles for the events to use with WaitForSingleObject?I should
probably need to create two handles (for example mhStopEvent and
mhStartEvent )right? and how should the OnBnStop() function looks
like?
Does anyone have a suggestion?
Thank you
Lucress