怎样终止由CWinThread派生出来的线程??????????? 怎样终止由CWinThread派生出来的线程???????????最好有例子。多谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先声明一个全局变量:extern CWinThread *pThread;//在.h中然后定义:CWinThread *pThread=NULL;//.cpp中在你的线程类的BOOL CMyThread::InitInstance()里加入: pThread=AfxGetThread();最后,在你要结束的地方加入: if(pThread) { DWORD exit; GetExitCodeThread(pThread->m_hThread,&exit); TerminateThread(pThread->m_hThread,exit); } 这样就结束了 c创建时保存句柄 然后最后用BOOL TerminateThread( HANDLE hThread, // handle to thread DWORD dwExitCode // exit code);关闭之 BOOL TerminateThread( HANDLE hThread, // handle to thread DWORD dwExitCode // exit code);CxxxThread m_thread;HANDLE hThread=m_thread.m_hThread;BOOL PostThreadMessage( UINT message , WPARAM wParam, LPARAM lParam );用WM_CLOSE不知道行不行,如果不行,重载PreTranslateMessage 要优雅的终止线程,你需要两个事件,一个是用于线程外部通知线程需要结束,另外一个是用与线程通知线程外部线程已经结束参见http://www.blogcn.com/blog/?u=jiangsheng在页面上查找AfxBeginThread 关于两个界面的按钮切换 简单问题,C++类的成员变量默认什么属性? 关于堆和new 帮办我吧!!我受不了了vc 关于子对话框的问题 在XP下有没有和98下inp函数功能类似的函数啊? 初学者疑问????????????急!!!!!!!! 发现VC可以在一个cpp中include另外一个cpp文件? 如何在程序中生成数据库源? 高手们,关于serverpush的问题,请帮忙!! cmsbai 接分!!! 如何用VC创建虚拟目录?
extern CWinThread *pThread;//在.h中然后定义:CWinThread *pThread=NULL;//.cpp中在你的线程类的BOOL CMyThread::InitInstance()里加入: pThread=AfxGetThread();最后,在你要结束的地方加入: if(pThread)
{
DWORD exit;
GetExitCodeThread(pThread->m_hThread,&exit);
TerminateThread(pThread->m_hThread,exit);
} 这样就结束了
BOOL TerminateThread(
HANDLE hThread, // handle to thread
DWORD dwExitCode // exit code
);关闭之
HANDLE hThread, // handle to thread
DWORD dwExitCode // exit code
);CxxxThread m_thread;
HANDLE hThread=m_thread.m_hThread;BOOL PostThreadMessage(
UINT message ,
WPARAM wParam,
LPARAM lParam
);
用WM_CLOSE不知道行不行,如果不行,重载PreTranslateMessage
参见http://www.blogcn.com/blog/?u=jiangsheng
在页面上查找AfxBeginThread