You must use a thread for that. In this example, I used only one button to start and cancel the thread.
in the .h of your dialog, add:
HANDLE m_hThread;
static DWORD WINAPI ThreadFunction(LPVOID param);
BOOL m_Cancel;
int the .cpp of your dialog, add:
CYourDialog::CYourDialog()
{
m_hThread = NULL;
m_Cancel = FALSE;
}
void CYourDialog::OnButtonStartOrCancelClicked()
{
if (m_hThread == NULL)
{
m_Cancel = FALSE;
m_hThread = CreateThread(NULL, 0, ThreadFunction, this, 0, NULL);
SetDlgItemText(IDC_BUTTON_START_OR_CANCEL, "Cancel");
}
else
{
m_Cancel = TRUE;
WaitForSingleObject(m_hThread, INFINIE);
CloseHandle(m_hThread);
m_hThread = NULL;
SetDlgItemText(IDC_BUTTON_START_OR_CANCEL, "Start");
}
}
DWORD WINAPI CYourDialog::ThreadFunction(LPVOID param)
{
CYourDialog* This = (CYourDialog*)param;
for (...)
{
...
if (This->m_Cancel)
{
break;
}
...
}
return 0;
}
Not understand please can you give details of this
If you don't know anything about threads, then have a look to this link as a start.
They are lots of articles on threading on CodeProjet or internet.
Creating Threads using the CreateThread() API[
^]