自定义消息和全局变量: #define WM_USERMSG WM_USER+100//自定义消息 volatile int SpeedControl;//定义全局变量 线程体: UINT ThreadFunc(LPVOID lpParam) //线程函数 { NumInfo* pInfo=(NumInfo*)lpParam; //线程函数参数 int i=0; CString str; while(true) { if(SpeedControl==1) //低速计数 { str.Format("%d",i); pInfo->pedit->SetWindowText(str); Sleep(2000); i++; if((i%17)==0)//计数到了17的整数倍 { ::PostMessage(pInfo->hwnd,WM_USERMSG,0,0); //向主线程发送消息 } } if(SpeedControl==2) //高速计数 { str.Format("%d",i); pInfo->pedit->SetWindowText(str); Sleep(250); i++; if((i%17)==0)//计数到了17的整数倍 { ::PostMessage(pInfo->hwnd,WM_USERMSG,0,0); //向主线程发送消息 } } if(SpeedControl==0) //暂停 { str.Format("%d",i); pInfo->pedit->SetWindowText(str); Sleep(200); } } return 0; } 主线程接收消息: LRESULT CMessageThreadDlg::OnMsg(WPARAM wParam,LPARAM lParam) { // TODO: Add your control notification handler code here AfxMessageBox("当前计数器的计数为17的整数倍");//提示对话框 return true; }