1 定义全局对象和线程函数
CWinThread *pThread = new CWinThread();
HWND pmain=NULL;
UINT StartAndCloseThreadProc(LPVOID)
{
int k=0;
CString STR=NULL;
while(1)
{
k++;
STR.Format("k=%d",k);
::SetDlgItemText(pmain,IDC_TEXT,STR);
::Sleep(10);
}
return 0;
}
2 线程暂停
pThread->SuspendThread();
3 线程继续执行
pThread->ResumeThread();
4 杀死线程
DWORD code;
BOOL res=false ;
res=GetExitCodeThread(pThread->m_hThread, &code);
if (!res && code==STILL_ACTIVE)//线程还活着
{
TerminateThread(pThread->m_hThread,1);
CloseHandle(pThread->m_hThread);
}
5 启动线程
pThread=AfxBeginThread(ScenceDisplay::AutoDisplay,this);