为什么我使用Sleep()函数后改变了我的CWnd指针对象的m_pCtrlSite的值
我想使用线程控制我的按钮的摆动,可是当我使用sleep函数后,我的CWnd *pWnd的m_pCtrlSize值被改变,使得程序无法继续,请问该如何解决 附件为挑出来的代码写的测试程序,也是同样的问题
部分代码如下:UINT ButtonFlutterThread(LPVOID pParam)
{
FLT_THREAD *pStruct =static_cast<FLT_THREAD *>(pParam);
CWnd *pWnd;
CRect rectMain,rectButton1,rectButton2,rectButton3,rectButton;
int offset=3;
pStruct->pViewWnd->GetWindowRect(rectMain);
pStruct->pWnd1->GetWindowRect(rectButton1);
pStruct->pWnd2->GetWindowRect(rectButton2);
pStruct->pWnd3->GetWindowRect(rectButton3);
while(WaitForSingleObject(pStruct->hEvent,0)==WAIT_TIMEOUT)
{
switch(*pStruct->pnThreadType)
{
case SHIJUANXINXI:
rectButton.left=rectButton1.left-rectMain.left;
rectButton.top=rectButton1.top-rectMain.top;
rectButton.right=rectButton1.right-rectMain.left;
rectButton.bottom=rectButton1.bottom-rectMain.top;
pWnd=pStruct->pWnd1;
break;
case JIANKAOXINXI:
rectButton.left=rectButton2.left-rectMain.left;
rectButton.top=rectButton2.top-rectMain.top;
rectButton.right=rectButton2.right-rectMain.left;
rectButton.bottom=rectButton2.bottom-rectMain.top;
pWnd=pStruct->pWnd2;
break;
case KAOCHANGANPAI:
rectButton.left=rectButton3.left-rectMain.left;
rectButton.top=rectButton3.top-rectMain.top;
rectButton.right=rectButton3.right-rectMain.left;
rectButton.bottom=rectButton3.bottom-rectMain.top;
pWnd=pStruct->pWnd3;
break;
default:
break;
}
pWnd->MoveWindow(rectButton.left-offset,rectButton.top+offset
,rectButton.Width(),rectButton.Height());
Sleep(200);
pWnd->MoveWindow(rectButton.left,rectButton.top,rectButton.Width()
,rectButton.Height());
Sleep(200);
pWnd->MoveWindow(rectButton.left+offset,rectButton.top+offset
,rectButton.Width(),rectButton.Height());
Sleep(200);
pWnd->MoveWindow(rectButton.left,rectButton.top,rectButton.Width()
,rectButton.Height());
Sleep(1000);
}
return true;
}
void CMyView::ButtonThreadInit(void)
{
m_pStruct->pViewWnd=(CWnd *)this;
m_pStruct->pWnd1=GetDlgItem(IDC_BUTTON_SHIJUAN);
m_pStruct->pWnd2=GetDlgItem(IDC_BUTTON_JIANKAO);
m_pStruct->pWnd3=GetDlgItem(IDC_BUTTON_KAOCHANG);
m_pStruct->hEvent=m_hEventFlutter;
m_wtFlutter=AfxBeginThread(ButtonFlutterThread,m_pStruct,THREAD_PRIORITY_ABOVE_NORMAL);
}
线程.rar
(56.66 KB)