communication method is something like this: When you create a thread you save the handle to the thread and use it to kill the thread somewhere
用TerminateThread试试看,注意这是一个API函数 BOOL TerminateThread( HANDLE hThread, // handle to the thread DWORD dwExitCode // exit code for the thread );或者,你在你的那个死循环里面加一个判断句
while (pparams.istatus=true)//这个istatus为一static,or global 变量 { } 按下那个对话框你改变那个istatus,这样就会结束死循环
something like this:
When you create a thread you save the handle to the thread
and use it to kill the thread somewhere
BOOL TerminateThread(
HANDLE hThread, // handle to the thread
DWORD dwExitCode // exit code for the thread
);或者,你在你的那个死循环里面加一个判断句
while (pparams.istatus=true)//这个istatus为一static,or global 变量
{ }
按下那个对话框你改变那个istatus,这样就会结束死循环
如果需要一个work线程,可以直接定义一个线程函数,然后直接用AfxBeginThread
启动即可,如下UINT WatchThread( LPVOID pvParam )
{
...
return TRUE;
}CWinThread *pThread;pThread = AfxBeginThread( (AFX_THREADPROC)WatchThread,
(LPVOID)m_ProcessInformation.hProcess,
THREAD_PRIORITY_NORMAL, 0,0, NULL );如果是开发UI线程,则你必须按照UI线程的开发步骤:
在InitInstance()中生成线程的主窗口
在ExitInstance()中销毁主窗口
通过消息映射机制,完成消息函数编写UI线程内部的消息推动机制类似CWinApp::Run()
通过向UI线程PostThreadMessage(WM_QUIT)从外部结束这个UI线程
也可以在UI线程内部使用PostQuitMessage结束自己
当要就是workerthread,在按钮控制函数里改变a的值:a = 1;
若如你所说的那样,workerthread里是一个死循环。则可以:{
......
if(a == 1)
AfxEndThread();
......
}
再请教一个问题,CWinThread里面有没有消息循环,我记得工作线程里面是没有消息循环的,只在用户界面线程里才有。那CWinThread里面有没有消息循环呢?
谢谢!