void lpRecvProc(LPVOID lpParam)
{
CEdit* pEdit=(CEdit*)lpParam;
long j;
CString str;
pEdit->GetWindowText(str);
j=atoi(str);
for(int i=0;i<100000;i++)
{
j++;
CString str1;
str1.Format("%d",j);
pEdit->SetWindowText(str1);
}
}
void CThreadTestDlg::OnStartbutton()
{
// TODO: Add your control notification handler code here
//先終止先前的進程
if(hThread)
TerminateThread(hThread,dwThreadId);
hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)lpRecvProc,&m_edit,0,&dwThreadId);
if(hThread==NULL)
AfxMessageBox("創建線程失敗!");
}
void CThreadTestDlg::OnEndbutton()
{
// TODO: Add your control notification handler code here
if(hThread)
TerminateThread(hThread,dwThreadId);
}
void CThreadTestDlg::OnPausebutton()
{
// TODO: Add your control notification handler code here
if(hThread)
SuspendThread(hThread);
}
void CThreadTestDlg::OnContinuebutton()
{
// TODO: Add your control notification handler code here
if(hThread)
ResumeThread(hThread);
}
void CThreadTestDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if(hThread)
TerminateThread(hThread,dwThreadId);
}