线程函数问题
描述:
MFC对话框工程,想用一个Edit控件实时显示线程函数中某个变量的实时值。
下面是个Demo代码:
void CThreadTestDlg::OnButton1()//启动线程 { // TODO: Add your control notification handler code here DWORD ThreadId; handleThread=::CreateThread(NULL,0,TestThreadProc,this,0,&ThreadId);}void CThreadTestDlg::OnButton2()//关闭线程{ // TODO: Add your control notification handler code here TerminateThread(handleThread,0);}DWORD WINAPI CThreadTestDlg::TestThreadProc(LPVOID lParam){ CThreadTestDlg *mainDlg=(CThreadTestDlg*)lParam; int iMsg=0; for (int i=0;i<65536;i++) { iMsg++; mainDlg->OnShowMsg(iMsg); } return 0;}void CThreadTestDlg::OnShowMsg(int iMsg){ m_strMsg.Format("%d",iMsg);//m_strMsg为Edit控件绑定变量 UpdateData(FALSE);}