首先看看OnTimer的做法。
1 在类中
void CMyDialog::OnTimer(UINT nIDEvent)
{
if (nIDEvent == MY_TIMER)
{
//process something
}
CDialog::OnTimer(nIDEvent);
}
BOOL CODM_DlgShowImage::OnInitDialog()
{
SetTimer(MY_TIMER, 500, NULL);
}
2
void CMyApp::CreateDlg ()
{
if (m_pDlg)
{
m_pDlg->DestroyWindow();
delete m_pDlg;
m_pDlg = NULL;
}
m_pDlg = new CMyDialog ();
m_ pDlg ->Create(CMyDialog::IDD);
m_ pDlg ->SetContainer(&m_container);
m_ pDlg ->ShowWindow(SW_HIDE);
}
这样做有什么问题呢,我们先不说,然后看看用线程的做法。
void CMyApp::CreateDlg ()
{
if (m_pDlg)
{
m_pDlg->DestroyWindow();
delete m_pDlg;
m_pDlg = NULL;
}
m_pDlg = new CMyDialog ();
m_ pDlg ->Create(CMyDialog::IDD);
m_ pDlg ->SetContainer(&m_container);
m_ pDlg ->ShowWindow(SW_HIDE);
AfxBeginThread(ThreadProc, this);
}
UINT CMyApp::ThreadProc(void* p)
{
CMyApp * CApp = (CMyApp *)p;
while(1)
{
if ()
{
//process something;
}
else
{
break;
}
Sleep(200);
}
return 0;
}
采用线程的方式解决了什么问题呢,大家可以思考一下。
转载请注明原创连接:http://blog.csdn.net/wujunokay/article/details/44783473