Click here to Skip to main content
15,921,212 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: loop speed Pin
locoone17-Jul-05 18:34
locoone17-Jul-05 18:34 
GeneralRe: loop speed Pin
khan++17-Jul-05 18:56
khan++17-Jul-05 18:56 
GeneralRe: loop speed Pin
locoone17-Jul-05 20:40
locoone17-Jul-05 20:40 
GeneralRe: loop speed Pin
khan++17-Jul-05 21:50
khan++17-Jul-05 21:50 
GeneralRe: loop speed Pin
locoone17-Jul-05 21:53
locoone17-Jul-05 21:53 
GeneralRe: loop speed Pin
khan++17-Jul-05 22:02
khan++17-Jul-05 22:02 
GeneralRe: loop speed Pin
locoone17-Jul-05 22:04
locoone17-Jul-05 22:04 
GeneralRe: loop speed Pin
khan++17-Jul-05 22:48
khan++17-Jul-05 22:48 
I assume this is your worker function:
void CMyDlg::Worker()
{
while (m_bWorking)
{
//processing here.
}
}

In your header file:
HANDLE m_hThread;
bool m_bWorking;
static DWORD __stdcall Thread(LPVOID lpVoid);

In your .cpp file:
DWORD __stdcall CMyDlg::Thread(LPVOID lpVoid)
{
CMyDlg* parent = (CMyDlg*)lpVoid;
parent->Worker();
return 0;
}

void CMyDlg::OnButtonStart()//your button handler function.
{
m_bWorking = TRUE;
m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id);
SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST);
ResumeThread(m_hThread);
}

void CMyDlg::OnButtonSuspend()//pause it
{
SuspendThread(m_hThread);
}

void CMyDlg::OnButtonResume()//resume it
{
ResumeThread(m_hThread);
}

void CMyDlg::OnButtonStop()//stop it
{
m_bWorking = false;
}

I hope that helps.


this is this.
GeneralRe: loop speed Pin
locoone17-Jul-05 23:25
locoone17-Jul-05 23:25 
GeneralRe: loop speed Pin
khan++17-Jul-05 23:35
khan++17-Jul-05 23:35 
GeneralRe: loop speed Pin
locoone18-Jul-05 0:00
locoone18-Jul-05 0:00 
GeneralRe: loop speed Pin
khan++18-Jul-05 0:13
khan++18-Jul-05 0:13 
GeneralRe: loop speed Pin
locoone18-Jul-05 0:15
locoone18-Jul-05 0:15 
GeneralRe: loop speed Pin
khan++18-Jul-05 0:23
khan++18-Jul-05 0:23 
GeneralRe: loop speed Pin
locoone18-Jul-05 0:25
locoone18-Jul-05 0:25 
GeneralRe: loop speed Pin
khan++18-Jul-05 0:36
khan++18-Jul-05 0:36 
GeneralRe: loop speed Pin
locoone18-Jul-05 1:04
locoone18-Jul-05 1:04 
GeneralRe: loop speed Pin
David Crow18-Jul-05 2:56
David Crow18-Jul-05 2:56 
GeneralRe: loop speed Pin
David Crow18-Jul-05 2:59
David Crow18-Jul-05 2:59 
GeneralRe: loop speed Pin
locoone18-Jul-05 17:46
locoone18-Jul-05 17:46 
GeneralRe: loop speed Pin
David Crow19-Jul-05 2:27
David Crow19-Jul-05 2:27 
Questionwhen the program is closed, why does the exception occur? Pin
liuyue16-Jul-05 23:42
liuyue16-Jul-05 23:42 
AnswerRe: when the program is closed, why does the exception occur? Pin
Jose Lamas Rios17-Jul-05 16:59
Jose Lamas Rios17-Jul-05 16:59 
GeneralCPU Serial number Pin
Abd.Eskandari16-Jul-05 21:50
Abd.Eskandari16-Jul-05 21:50 
GeneralRe: CPU Serial number Pin
Alexander M.,17-Jul-05 6:02
Alexander M.,17-Jul-05 6:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.