void CUIThreadDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
//this->DestroyWindow();
//this->EndDialog(0);
//this->PostMessage(WM_DESTROY);//WM_DESTROY
CDialog::OnClose();
//MyBeep(2);
this->PostMessage(WM_QUIT);
}
BOOL CUIThread::InitInstance()
{
// TODO: perform and per-thread initialization here
m_dlg.Create(IDD_UITHREADDLG);
m_dlg.ShowWindow(SW_SHOW);
m_pMainWnd=&m_dlg;
return TRUE;
}
void MyBeep(int times)
{
for(int i=0;i<times;i++)
{
::Beep(200,50);
Sleep(1000);
}
}
int CUIThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
MyBeep(3);//要在对话框关闭时发送WM_QUIT消息将线程结束,才会调用CUIThread::ExitInstance
m_dlg.DestroyWindow();
return CWinThread::ExitInstance();
}
void TestFunction()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWinThread *pThread=AfxBeginThread(RUNTIME_CLASS(CUIThread));
return;
}