/退出线程
void CThreadTest::OnButton2()
{
g_exitThread=TRUE; //设置全局变量为真,令线程退出
#if 1
WaitForSingleObject(m_pThread1->m_hThread,INFINITE); //无限等待
#else
DWORD dRet;
MSG msg;
while (1)
{
dRet=::MsgWaitForMultipleObjects(1,&m_pThread1->m_hThread,FALSE,INFINITE,QS_ALLINPUT);
if (dRet == WAIT_OBJECT_0+1)
{
while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
break;
}
}
#endif
}
/
BOOL bIsok = TRUE;
while(bIsok)
{
DWORD dwTime = MsgWaitForMultipleObjects(1,&hEventOk,FALSE, 10, QS_ALLINPUT);
MSG msg;
//等到信号
switch(dwTime)
{
case WAIT_OBJECT_0:
{
bIsok = FALSE;
}
break;
case WAIT_OBJECT_0+1:
{
//有消息
if(PeekMessage(&msg,NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
break;
case WAIT_TIMEOUT:
{
//超时处理
}
break;
}
}
https://www.cnblogs.com/shangdawei/p/4015772.html