// 假设你的应用程序类为 CMyApp,线程类为 CMyThread
#include "CMyApp.h"
#include "CMyThread.h"
BOOL CMyApp::InitInstance()
{
// 创建并运行新线程
CMyThread* pThread = (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread));
// 其他初始化工作...
return TRUE;
}
int CMyThread::ExitInstance()
{
// 在线程退出时执行清理工作
// 例如,释放资源
if (m_someResource != nullptr)
{
delete m_someResource;
m_someResource = nullptr;
}
return CWinThread::ExitInstance();
}
在上述代码中,ExitInstance 被重载以执行在线程退出时的清理工作。你可以在这个函数中释放资源、关闭文件、清理数据结构等。确保在最后调用 CWinThread::ExitInstance(),以确保 MFC 执行默认的清理操作。
请注意,这只是一个简单的示例,实际的清理工作可能取决于你的应用程序的具体需求。
转载请注明出处:http://www.zyzy.cn/article/detail/23224/MFC/CWinThread