Pausing and continuing MFC Thread

L

Lucress Carol

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top