单击按钮后,创建线程
线程函数
void CRandom_CreatDlg::OnButtonStart()
{
// TODO: Add your control notification handler code here
if (!image.isStart)
{
image.isStart=true;
pThread=AfxBeginThread(ThreadDisplay,&image,THREAD_PRIORITY_NORMAL);
}
else
image.isStart=false;
}
线程函数
UINT ThreadDisplay(LPVOID param)
{
ImageInfo *pImage=(ImageInfo*)param;
if (pImage->m_ImagePathAry.GetSize()==0)
{
return FALSE;
}
while(pImage->isStart)
{
srand(time(NULL));
CDC *pDC=pImage->pWnd->GetDC();
Graphics graph(pDC->GetSafeHdc());
int m_rand=rand()%pImage->m_ImagePathAry.GetSize();
WCHAR* path=pImage->m_ImagePathAry[m_rand].AllocSysString();