双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

线程跨类无法关闭的问题???

mirro187_ mirro187_ 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

MainFrame类里
CWinThread* pThread = NULL;//全局变量


void CMainFrame::OnManageUser()//工具栏的按钮按下消息,弹出对话框并触发一个线程。
{
if(!ShowObj.ShowWindow(SW_SHOW))
{
pThread = AfxBeginThread((AFX_THREADPROC)MyThreadProc,GetSafeHwnd());
// pThreadOut = pThread;
// bflagTime = TRUE;
}
}


UINT WINAPI MyThreadProc(LPVOID pParam)
{

while(1);
}

//对话框类里关闭消息关闭线程,关闭不了。卡住并强制关闭程序。。。。

extern CWinThread* pThread;

void AlarmDlg::OnClose()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
DWORD dwECode;
GetExitCodeThread(pThread->m_hThread,&dwECode);
if(dwECode == STILL_ACTIVE)
{
TerminateThread(pThread->m_hThread,0);
CloseHandle(pThread->m_hThread);
pThread->m_hThread = NULL;
}
CDialog::OnClose();
}



::AfxEndThread(0);//随便问下,这种关闭线程的方法怎么连个线程句柄都不需要指定呢????
...全文
评论 6
收藏 已收藏
分享
返回顶部
mirro187_
进程/线程/DLL 15,466 成员 49,169 内容